Hell everyone. I need some help with a ruby script that I am writing that doesn't seem to be working. Simply put, I am getting an error when using Rufus to schedule something to happen "at" a specific time.
Here is my code.
starttime = Time.new + (60)
scheduler = Rufus::Scheduler.start_new
scheduler.at starttime do
Curl::Easy.download(url, filename = "/tmp/test.xml")
end
While that works, it errors out after it's first run with the following:
================================================================================
scheduler caught exception:
can't convert nil into String
/Users/me/.gem/ruby/1.9.1/gems/curb-0.8.0/lib/curl/easy.rb:38:in `add'
/Users/me/.gem/ruby/1.9.1/gems/curb-0.8.0/lib/curl/easy.rb:38:in `perform'
/Users/me/.gem/ruby/1.9.1/gems/curb-0.8.0/lib/curl/easy.rb:358:in `download'
/Users/me/Dropbox/Files/Personal/RubyMine/hbo_hackathon/SOME:19:in `block (2 levels) in <top (required)>'
I am pretty new to Ruby (and development in general), so I am not sure why this is happening. Can someone help please?
Also, the real goal here is to replace this line:
starttime = Time.new + (60)
With this line:
starttime = REXML::XPath.first( doc, '/new/time/text()')
The reason for this, is because I want to pull a dynamic time out of some XML (in this case, a message from a Amazon SQS queue that I subscribe to), and tell it to curl a URL at a specific time. That is the real reason that I am trying to get this working.
When I try to pass the time from the XML, I get a completely different error. I have tried sending every type of time format possible, but it still gives me an error. Please help!
/Users/me/.gem/ruby/1.9.1/gems/rufus-scheduler-2.0.16/lib/rufus/sc/rtime.rb:327:in `at_to_f': cannot determine 'at' time from : "1334865999.4416242" (ArgumentError)
from /Users/me/.gem/ruby/1.9.1/gems/rufus-scheduler-2.0.16/lib/rufus/sc/jobs.rb:253:in `determine_at'
from /Users/me/.gem/ruby/1.9.1/gems/rufus-scheduler-2.0.16/lib/rufus/sc/jobs.rb:90:in `initialize'
from /Users/me/.gem/ruby/1.9.1/gems/rufus-scheduler-2.0.16/lib/rufus/sc/me.rb:149:in `new'
from /Users/me/.gem/ruby/1.9.1/gems/rufus-scheduler-2.0.16/lib/rufus/sc/scheduler.rb:149:in `at'
from /Users/me/Dropbox/Files/Personal/RubyMine/hbo_hackathon/SOME:18:in `block in <top (required)>'
OK,
the first error is not related to rufus-scheduler. It's probably you passing a nil "url" to the Curl library.
The second error
cannot determine 'at' time from : "1334865999.4416242" (ArgumentError)
is rufus-scheduler complaining about getting passed a string it cannot turn into a Time instance.
Try something like
starttime = REXML::XPath.first(doc, '/new/time/text()').to_f
So, to summarize, you're seeing two different errors. Fix them one after the other. Start with the one at the heart : Curl complaining about some nil passed instead of a string, then look at the starttime issue.
Cheers,
John