Class: Junkie::Pyload::Observer

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

Constant Summary collapse

DEFAULT_CONFIG =
{
    watchdog_refresh: 10,          # interval the watchdog_timer is fired
    dont_add_episodes_to_queue: false,
}

Instance Attribute Summary collapse

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

#initialize(channels) ⇒ Observer

Returns a new instance of Observer.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/junkie/pyload/observer.rb', line 17

def initialize(channels)
  @config = Config.get_config(self)

  @api = Junkie::Pyload::Api.new

  @channels = channels

  @found_episodes = Array.new

  @active_episode = nil

  @ready_for_new_links = true
  @watchdog_enabled = false
  @skipped_timer_at_first_complete_detection = false
  @should_stat_queued_episodes = false

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

    log.info("Got episode from Channel: #{episode}")
    @found_episodes.push(episode)
    stat_queued_episodes
  end
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



10
11
12
# File 'lib/junkie/pyload/observer.rb', line 10

def api
  @api
end

Instance Method Details

#setupObject

is a method that is called once from inside the reactor and allows us to register custom actions into the reactor



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/junkie/pyload/observer.rb', line 45

def setup
  in_fiber {
    @api.
    cleanup
    stat_queued_episodes
    stat_current_download
  }

  EM.add_periodic_timer(@config[:watchdog_refresh]) do
    monitor_progress if @watchdog_enabled

    if @should_stat_queued_episodes
      stat_queued_episodes
      @should_stat_queued_episodes = false
    end

    if not @config[:dont_add_episodes_to_queue]
      in_fiber { add_next_episode_to_pyload }
    end
  end
end