A
A
Alexander Leonchik2017-06-19 13:51:23
PostgreSQL
Alexander Leonchik, 2017-06-19 13:51:23

What is the best way to store crontime in database?

There is a table, let's say Emails, which stores email addresses.
The site interface has a form that specifies the "interval" for each email address in crontime format.:

Example
email            | timeline
[email protected] | */5 * * * *

*/5 * * * * - указывает на то что данная запись в базе должна находится каждый раз, когда текущее время/минуты кратны 5

Question: how to store this interval, taking into account the fact that the worker, by cron, every minute, should quickly find the tasks that need to be completed at that moment? What do you think of the current approach?
If there are other implementation options, I'll be happy to listen.
PS How does it work at the moment
Храню в базе интервал в crontime формате, за исключение того что записи в духе */5 конвертирую в 5,10,15....
Далее Postgres, запрос по регулярке (timeline ~* regxp):
  • Время: Mon, 19 Jun 2017 13:15:37
  • Регулярка: ^([\d,]*15[\d,]*|\*|15) ([\d,]*13[\d,]*|\*|13) ([\d,]*19[\d,]*|\*|19) ([\d,]*6[\d,]*|\*|6) ([\d,]*1[\d,]*|\*|1)$

Находит, отнасительно шустро, но мне сам подход не очень нравится

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ildar, 2017-06-19
@vistoyn

Use the mtdowling/cron-expression library .
She knows how to analyze cron-style intervals.
Idea such:
1. It is necessary to pull out all records from basis.
2. For each entry, find out the next start time.
3. If it matches the current minute, then complete the task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question