Closed berfarah closed 9 years ago
You're not missing anything; I was clearly smoking crack when I wrote this. :)
You can't serialize a block[1], so I'm not sure what I was thinking when I added the ability to schedule a block that's not attached to a class. The Delayed::Task.schedule
method does take an optional name, in which case it defines a class with that name on-the-fly, but the implementation is broken, and it's problematic anyway, because this class is only defined in the Ruby environment where you call schedule
. If you run your delayed jobs on a separate host, or in a separate Ruby process, it still won't be able to deserialize the job.
I'm going to get rid of Delayed::Task
. Use this instead:
class BerfarahsJob
include Delayed::RecurringJob
def perform
start_instance
run script
finish_instance
end
end
BerfarahsJob.schedule(options)
Thanks for reporting the issue, and sorry for the inconvenience!
[1] That's not 100% true; one could take a block and decompile it, e.g. see http://stackoverflow.com/questions/199603/how-do-you-stringize-serialize-ruby-code — but this is probably outside the scope of this gem.
Haha awesome, thanks @afn. I figured there was some Black Magic™ with memory caching or something since I couldn't figure out how it worked.
For my purposes, I suppose I'll be overwriting #jobs
to only look for jobs in a matching queue, since the reason I wanted to use dynamic classes was to keep track of individual instances.
Hi! I'm trying to use your on-the-fly scheduler like this:
Where I access the database before and after running to log whether an instance is running and send it to another class in between to run a bash script.
When I deserialize the class manually, I get:
What am I missing?