Answer the question
In order to leave comments, you need to log in
Laravel >=5. How to create/delete cron jobs on the fly?
Hello!
In short , when creating a new element, you need to create a cron task associated with it, which will start at a certain time (each element has a different start time) and stop running on an event on the server (for example, on an ajax request).
Read more . Let's say we have a model for creating meetings/conferences "Meeting". Among the parameters of each meeting is the date and time of its start ( $meeting->start_date ) and a boolean flag indicating that the meeting is completed ( $meeting->completed ). When creating a new meeting, you need to create a cron task for it, which will monitor data related only to it every minute (for example, the activity of meeting participants). And when the meeting ends (when $meeting->comleted === true ) the cron task of the meeting should be terminated.
How would you approach solving such a problem (not necessarily in detail - at the algorithm level)? And is it possible to do with one cron task?
Thanks in advance for any helpful hints.
UPD: Events are now prepared (MeetingCreated, MeetingUpdated, MeetingDeleted) and there is a command meeting:start {meeting_id}. But there is a problem with calling the meeting:start command from the Job at a specific time
Answer the question
In order to leave comments, you need to log in
I am using node.js for something like this. Here is my advice to look.
It seems to me that it will be better + there is no load)
Look towards сron.js
Already crush similar
One cron task. Kind of a conveyor. Run often. For example, once every 30 seconds. And process all objects
I did it differently, but it doesn't always work. Making a mutator
protected $appends = ['status'];
function getStatusAttribute() {
if ($this->start_date >= Carbon::today()->toDateString() or $this->start_date == NULL) {
return 1;
} else {
return 0;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question