Answer the question
In order to leave comments, you need to log in
How to improve the architecture of the deferred tasks service?
It is necessary to implement a service that performs http requests at a certain time. The timer is set by sending a message through a queue (RabbitMQ).
The service is a job-server with the exact start time of the task.
The best solution I could come up with was to store the received tasks in a database. Each task has an absolute start time. A separate daemon periodically (for example, once per second/) selects from the database tasks whose expiration date is less than the current time + duration of the expiration period. If entries are found, run a query for each of the tasks. Repeat cycle.
Adding tasks to the pool (DB) is carried out by a separate daemon listening to the queue.
Requirements:
- the minimum period between adding a task and its triggering is 30 seconds
- the accuracy of specifying the trigger time - 1 sec
- the maximum timer setting period - unlimited
- the order of triggering depends only on the trigger date, but does not depend on the order in which they entered the pool
- language for implementing the service - php 5.6
Are there any more optimal / efficient options? Maybe there are ready-made solutions? Or can my version be improved?
Answer the question
In order to leave comments, you need to log in
Create a console application with an infinite loop.
Which waits for the next event, as soon as it arrives it makes an http request and takes the next event.
When a new task appears, after adding it, it is necessary to send a signal to the process (which is waiting for the next event) so that it rereads and takes the next next event.
Technologies for writing demons https://daemon.io/ or reactphp.org you can also read about creating demons in php, but php is not the best language for this task, a small task can be implemented on anything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question