M
M
Maria Ramona2019-06-06 20:41:54
PHP
Maria Ramona, 2019-06-06 20:41:54

Task queues. What is the best way to send booking reminders?

There is a service for renting housing in php 7.x, it is possible to book for any date in the future. It is necessary for everyone who made a reservation to remind about it a week before the date of settlement and one day before this date, by sending an e-mail.
The service is quite high-loaded, up to several thousand bookings per day. Therefore, stupidly setting a task in cron for each booking is not an option.
What are the implementation ideas? Preferably only using cron and Redis, and some library for redis+php.
It is also necessary to provide that the booking can be canceled / rescheduled, then sending a reminder is also canceled / rescheduled.
Initially, there was an idea that a Redis entry is added directly when booking, and a task is assigned to cron to view these entries once a day and send out reminders about bookings that are due, but it was decided to consider more options.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Kubintsev, 2019-06-11
@MariaRamona

Why use Redis here? In my opinion, it is much more convenient to store the queue in the DBMS in such a format that there is a time field after which the letter must be sent.
At the same time, several cron instances can be taught to work with this plate in parallel, for which, of course, you need to store the is_locked attribute.
And of course, you need to write a separate cron to clear the table from old completed tasks.

I
Ivan Shumov, 2019-06-06
@inoise

Collect jobs from cron and put them in a queue (Redis is fine, but RabbitMQ is better). And on the other side of the queue, put as many handlers as you need and send them out. Creating tasks will be much faster than sending a lot of notifications to the outside world

A
AN, 2019-06-07
@AlekseyNikulin

Maria Ramona , you can parallelize processes so that the process does not drag out in one thread. Create a master process that will start multiple children.
According to the architecture, decide for yourself how many records you will choose. Don't forget to set up read locks to prevent children from reading already taken records.
The library can be taken here . Works asynchronously.
Well, there are a number of libraries for working with tasks:
1. https://github.com/chrisboulton/php-resque
2. https://packagist.org/packages/woojean/php-redis-queue
This list is not complete.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question