lib/junkie/reactor.rb in junkie-0.0.12 vs lib/junkie/reactor.rb in junkie-0.0.13

- old
+ new

@@ -37,38 +37,11 @@ @found_episodes = Hash.new build_procs # has to be called here end - def build_procs - # Proc that looks for new episodes on Seriesjunkies.org and adds them to - # the episode_queue if they are new - @look_for_new_episodes = Proc.new { - in_fiber { - - log.debug "Reload Sindex from file" - # TODO refactor this so that we can detect if we have to reload the - # index (by MD5sum) - sindex = Sindex::SeriesIndex.new(index_file: @config[:series_index_file]) - sjunkieex = Sjunkieex::Interface.new(sindex) - - log.info "Looking for new episodes" - sjunkieex.get_links_for_downloads.each do |episode| - identifier = "%s@%s" % [episode.id, episode.series] - - if not @found_episodes.has_key? identifier - log.info("Found new episode '#{episode}'") - - @channels[:episodes].push(episode) - @found_episodes[identifier] = episode - end - end - } - } - end - ########################################################################### #################### The Reactor ########################################## ########################################################################### def start @@ -94,8 +67,51 @@ end # start the web interface Junkie::Webinterface::Interface.setup(@channels) end + end + + private + + def build_procs + + # Proc that looks for new episodes on Seriesjunkies.org and adds them to + # the episode_queue if they are new + @look_for_new_episodes = proc { + + operation = proc { + log.debug "Reload Sindex from file" + sindex = Sindex::SeriesIndex.new(index_file: @config[:series_index_file]) + + sjunkieex = Sjunkieex::Interface.new(sindex) + + log.info "Looking for new episodes" + sjunkieex.get_links_for_downloads + } + + callback = proc { |episodes| + + episodes.each do |episode| + identifier = "%s@%s" % [episode.id, episode.series] + + if not @found_episodes.has_key? identifier + log.info("Found new episode '#{episode}'") + + @channels[:episodes].push(episode) + @found_episodes[identifier] = episode + end + end + + # send out the current time out of the websocket + @channels[:info].push({ + key: "Last Episode Search", + desc: "The last time <strong>junkie</strong> has searched for new episodes", + value: Time.new.strftime("%d.%m.%Y %H:%M:%S") + }) + } + + EM.defer(operation, callback) + } end end end