jmettraux/rufus-scheduler

pre triggers don't have access to keywords on the first run

jjb opened this issue · 2 comments

jjb commented

While playing around with the name idea discussed in #309, and first seeing how I liked the existing keys facility, I made the following script

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

def scheduler.on_pre_trigger(job, t)
  puts "pretrigger: #{job[:name]}"
end

scheduler.every '1s' do |job|
  job[:name] = "the name"
  puts 'Hello... Rufus'
end

scheduler.join

which produces this output

➔ bundle exec ruby code.rb
pretrigger:
Hello... Rufus
pretrigger: the name
Hello... Rufus
pretrigger: the name
Hello... Rufus
pretrigger: the name
Hello... Rufus
pretrigger: the name
Hello... Rufus

Note that the first iteration doesn't have name assigned. I think this maybe indicates a bug?

Since the name is assigned in the trigger, I think it's totally normal it's not present before it's assigned.

jjb commented

Gotcha - in the light of day I realize I was thinking of them as "job attributes", but really they are "job-local variables" which persist across runs, as the docs say.