Class: Junkie::Pyload::Observer
- Inherits:
-
Object
- Object
- Junkie::Pyload::Observer
- Defined in:
- lib/junkie/pyload/observer.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ watchdog_refresh: 10, # interval the watchdog_timer is fired }
Instance Method Summary collapse
-
#add_episode(episode) ⇒ Object
Adds new episode to Pyload which downloads the episode and extracts it.
-
#initialize(config = {}) ⇒ Observer
constructor
A new instance of Observer.
-
#is_ready? ⇒ Boolean
checks if the Observer is ready to add new episodes to Pyload.
-
#setup ⇒ Object
is a method that is called once from inside the reactor and allows us to register custom actions into the reactor.
Methods included from Log
Methods included from Helper
Methods included from Config
collect_default_configs, get_config, included
Constructor Details
#initialize(config = {}) ⇒ Observer
Returns a new instance of Observer.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/junkie/pyload/observer.rb', line 14 def initialize(config={}) @config = Config.get_config(self) @api = Junkie::Pyload::Api.new @ready_for_new_links = true @watchdog_enabled = false @active_downloads = Hash.new @skipped_timer_at_first_complete_detection = false end |
Instance Method Details
#add_episode(episode) ⇒ Object
Note:
should only be called if ‘is_ready?` returns true
Adds new episode to Pyload which downloads the episode and extracts it
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/junkie/pyload/observer.rb', line 44 def add_episode(episode) raise InvalidStateError, "Observer is not ready" unless is_ready? @ready_for_new_links = false episode.status = :downloading package = "%s@%s" % [ episode.id, episode.series ] pid = @api.call(:addPackage, {name: package, links: [episode.link]}) @active_downloads[pid] = episode log.info("Added #{episode} to Pyload, Pid=#{pid}") (@watchdog_enabled = true) unless @watchdog_enabled end |
#is_ready? ⇒ Boolean
checks if the Observer is ready to add new episodes to Pyload
64 65 66 |
# File 'lib/junkie/pyload/observer.rb', line 64 def is_ready? @ready_for_new_links end |
#setup ⇒ Object
is a method that is called once from inside the reactor and allows us to register custom actions into the reactor
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/junkie/pyload/observer.rb', line 28 def setup in_fiber { @api.login cleanup } EM.add_periodic_timer(@config[:watchdog_refresh]) do monitor_progress if @watchdog_enabled end end |