I am starting many scheduled jobs at the same time using rufus scheduler. I want a variable in that code that will be available to only that scheduled job, when it runs again after some time.
how can i maintain a variable for for each scheduled job?
I am starting many scheduled jobs at the same time using rufus scheduler. I want a variable in that code that will be available to only that scheduled job, when it runs again after some time.
how can i maintain a variable for for each scheduled job?
Copyright © 2021 Jogjafile Inc.
there multiple ways to do that. I'll detail some of those, going from ugly to somehow elegant.
Solutions tested against Ruby 1.9.3p392 on Debian GNU/Linux 7 with rufus-scheduler 2.0.23 (https://rubygems.org/gems/rufus-scheduler).
You could use a global variable:
Or you could centralize the job variables in a single global variable (note: this isn't thread-safe):
One step further, just for fun (but still not thread-safe):
Finally, you could add a #vars to the Job class:
This is the solution I prefer. I intend to add a similar bag of variables to Job in rufus-scheduler 3.0 (https://github.com/jmettraux/rufus-scheduler).
You could also put the variable somewhere else and use the job_id / job.object_id as a key to retrieve it (as the first snips of code do).
I hope this will help.