0

I have a therapist system and each therapist add a session with its time when a client book a session i run a queued job to remind the client and doctor

  1. when the session starts
  2. before the session start with 3 hours
  3. before the session start with 1 hour

here is an example of my code

if($this->timeslot->last_charge_type == 'success'){
    dispatch(new SessionReminderJob($this->timeslot, $patient, $doctor))
            ->delay($this->timeslot->start_time->subHour());
    dispatch(new SessionReminderJob($this->timeslot, $patient, $doctor))
            ->delay($this->timeslot->start_time->subHours(3));
}

my problem is when a client wants to reschedule this session how to stop all of these jobs and run a new one with the new time.

I searched for some answers here but not efficient for my case like this

  1. question 1
  2. another one in laracasts
Joseph
  • 5,644
  • 3
  • 18
  • 44
  • This is not a task that is appropriate for the queue. I would recommend using the [scheduler](https://laravel.com/docs/8.x/scheduling) to schedule a single task to gather all upcoming appointments and dispatch the job with immediate effect. Alternatively you could check if the appointment time is in 1 or 3 hours as part of `SessionReminderJob` and choose to actually notify at that point if it still is – apokryfos Dec 23 '20 at 21:18
  • @apokryfos i check `scheduler` before using `queued jobs` but when i try it should work every 5 minutes and this will not be efficient let assume that the session table has about 1 million rows so in this case you need to iterate through these rows every 5 min? – Joseph Dec 24 '20 at 08:06
  • 1
    Simple SQL query filtering date/times should be efficient assuming correct indices are used. 1 million rows or 1 billion rows should not be much of a factor here if your database system is correctly utilised. Also (worse case) you can have only active sessions (i.e. upcoming sessions) in the table further removing the things in the table if that's a real concern. – apokryfos Dec 24 '20 at 08:16
  • in this case, should i add `index` to the `start_time` column? – Joseph Dec 24 '20 at 08:26
  • 1
    Yes that could help but most helpful is to fill the table with test data and time some queries and do `explain` on the slowest running queries you want to optimize to see what else can be done. – apokryfos Dec 24 '20 at 08:37

0 Answers0