Class: Junkie::Reactor

Inherits:
Object
  • Object
show all
Includes:
Config, Helper, Log
Defined in:
lib/junkie/reactor.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  :series_index_file  => File.join(Dir.home, '.sindex/seriesindex.xml'),
  :episode_search_refresh      => 15, # in minutes
}

Instance Method Summary collapse

Methods included from Log

#log

Methods included from Helper

#in_fiber

Methods included from Config

collect_default_configs, get_config, included

Constructor Details

#initializeReactor

Returns a new instance of Reactor.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/junkie/reactor.rb', line 24

def initialize
  @config = Config.get_config(self)

  log.info("Starting Junkie #{Junkie::VERSION}")

  @channels = {
      episodes: EM::Channel.new,
      notifications: EM::Channel.new,
      info: EM::Channel.new,
  }

  @pyload_observer = Junkie::Pyload::Observer.new(@channels)
  @twitter_notification = Junkie::Notification::Twitter.new(@channels)
  @dumper = Junkie::Notification::Dumper.new(@channels)

  @found_episodes = Hash.new
  build_procs # has to be called here
end

Instance Method Details

#startObject

The Reactor ##########################################



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/junkie/reactor.rb', line 47

def start

  EM.run do

    @channels[:episodes].subscribe do |episode|
      next unless episode.status == :extracted

      @channels[:notifications].push(episode)
    end

    # do some initialization work
    @pyload_observer.setup

    # Look for new episodes and add them to the Queue if they haven't
    # been found yet
    EM.next_tick do
      @look_for_new_episodes.call

      EM.add_periodic_timer(@config[:episode_search_refresh] * 60) do
        @look_for_new_episodes.call
      end
    end

    # start the web interface
    Junkie::Webinterface::Interface.setup(@channels)
  end
end