Issue
I am trying to manually start a cron job by hitting an endpoint on a controller that uses the SchedulerRegistry class to start the job. I am expecting Hello World! to be logged by the cron job but nothing happens.
From debugging I can see that the job is not undefined when pulling it in with the SchedulerRegistry so I'm not sure why it's not running. Any ideas?
Minimal Reproduction Here: https://gitlab.com/hactaviusxi/test-cron
Solution
job.start()
restarts a job that has been stopped.
The getCronJob() method returns the named cron job. The returned CronJob object has the following methods:
stop() - stops a job that is scheduled to run.
start() - restarts a job that has been stopped.
setTime(time: CronTime) - stops a job, sets a new time for it, and then starts it
lastDate() - returns a string representation of the last date a job executed
nextDates(count: number) - returns an array (size count) of moment objects representing upcoming job execution dates.
That's from the docs. Seems like you might want to use setTime
instead of start
, or create a new CronJob()
and reference the method you want to run as the handler for the job.
Answered By - Jay McDoniel Answer Checked By - Mary Flores (WPSolving Volunteer)