Class: Kaede::Updater
- Inherits:
-
Object
- Object
- Kaede::Updater
- Defined in:
- lib/kaede/updater.rb
Constant Summary collapse
- JOB_TIME_GAP =
seconds
15
Instance Method Summary collapse
-
#initialize(db, syobocal) ⇒ Updater
constructor
A new instance of Updater.
- #reload_scheduler ⇒ Object
- #update ⇒ Object
- #update_job_for(program) ⇒ Object
- #update_program(program, channel, tracking_titles) ⇒ Object
Constructor Details
#initialize(db, syobocal) ⇒ Updater
Returns a new instance of Updater.
8 9 10 11 |
# File 'lib/kaede/updater.rb', line 8 def initialize(db, syobocal) @db = db @syobocal = syobocal end |
Instance Method Details
#reload_scheduler ⇒ Object
54 55 56 57 58 59 |
# File 'lib/kaede/updater.rb', line 54 def reload_scheduler service = ::DBus.system_bus.service(DBus::DESTINATION) scheduler = service.object(DBus::Scheduler::PATH) scheduler.introspect scheduler.Reload end |
#update ⇒ Object
13 14 15 16 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/kaede/updater.rb', line 13 def update channels = {} @db.get_channels.each do |ch| channels[ch.for_syoboi] = ch end tracking_titles = Set.new(@db.get_tracking_titles) jobs = {} @db.get_jobs.each do |job| jobs[job[:pid]] = job end programs = @syobocal.cal_chk(days: 7) @db.transaction do programs.each do |program| if channels.has_key?(program.channel_for_syoboi) update_program(program, channels[program.channel_for_syoboi], tracking_titles) end jobs.delete(program.pid) end end jobs.each_value do |job| puts "Program #{job[:pid]} has gone away. Delete its job" @db.delete_job(job[:pid]) end reload_scheduler end |
#update_job_for(program) ⇒ Object
50 51 52 |
# File 'lib/kaede/updater.rb', line 50 def update_job_for(program) @db.update_job(program.pid, program.start_time + program.start_offset - JOB_TIME_GAP) end |
#update_program(program, channel, tracking_titles) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/kaede/updater.rb', line 42 def update_program(program, channel, tracking_titles) @db.update_program(program, channel) if tracking_titles.include?(program.tid) update_job_for(program) end end |