-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please mention somewhere that construction parameters should not be declared on Job class #35
Comments
It does, but yes, it should be made clearer that if you do want to use constructor arguments, a) they must have default parameters, as the JobService will re-create the job class passing through no constructor params The kind of logic to use in your constructor could be something like public function __construct($to = null) {
if ($to) {
// we know that we've been called by user code, so
// do the real initialisation work
}
} Of course, the other alternative is to set properties on the job directly after constructing it from your own code. |
Actually, this was mentioned in the wiki, but I've made it a bit clearer, and referenced it from the README file |
@nyeholt thanks for somewhat clarifying this, but where exactly can I put the parameters passed in to the constructor of the job in order to persist / make this information available to the running of it across multiple steps? For example public function __construct($startDate = null, $endDate = null). I want the start and end dates available in the process() function. Is there something built in to the queued jobs to do this, or will I have to think up my own way of storing the parameters (in DB or file) and then loading them back in the setup() function? Any guidance you can give on this would be greatly appreciated. Thanks. |
I've made it a little clearer in the wiki page, and copy / pasted below Job Properties QueuedJobs inherited from the AbstractQueuedJob have a default mechanism for persisting values via the __set and __get mechanism that stores items in the jobData map, which is serialize()d between executions of the job processing. All you need to do from within your job is call |
Took me a while before I figured out that this does not work :
The text was updated successfully, but these errors were encountered: