D
D
Dasha2015-11-08 14:53:39
MySQL
Dasha, 2015-11-08 14:53:39

How to make a timer for each entry in the database?

Hello!
There is an online store on Laravel 4.2, a MySQL database and a mobile application (for couriers).
Each order must be delivered within a limited time. Those. need a timer. After a limited time, you need to send push notifications to mobile phones, and mark the order as expired in the database.
I wonder how this can be implemented?
And the bottom line is that the customer wants the timer to be on the server because he does not trust the client :)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
J
JhaoDa, 2015-11-08
@bizzi

Queues can be added to the proposed options : they created an order, added a task to the queue with the desired delay . The job fires, marks the order, and sends a notification. If the order is delivered before the job has run, then the job can be deleted (not all queuing servers support).

A
Alexey Ukolov, 2015-11-08
@alexey-m-ukolov

1. Create a cron command that will check for expiration and send notifications.
2. Profit.

A
Alexander Latyshev, 2015-11-08
@magalex

Such things are implemented using the cron task scheduler.

A
Alexander Gubarev, 2015-11-08
@AlexGx

There are many implementation options, using a queue with timers, receiving events from the database, writing your own service responsible for this, cron. I would implement a console script that wakes up every 20-30 seconds (I think high precision is not needed) and processes records from the database, sends push notifications, and so on.

A
Alexander Kubintsev, 2015-11-08
@akubintsev

In essence, the use of a service based on an event loop is best seen. Technically - libevent. Around this library there are Node.js, and ReactPHP, and other PLs. The good thing is that it does not load the system. Accordingly, it is quite easy to write your own daemon that will register timers and execute handlers (like onExpire, getRemainingTime).
Use a queue manager like ZeroMQ or RabbitMQ or Redis to communicate with the daemon

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question