2021-03-09 00:18:33 +01:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from platypush.cron import cron
|
|
|
|
|
2022-04-28 00:57:49 +02:00
|
|
|
from tests.test_cron import test_timeout, cron_queue
|
|
|
|
|
|
|
|
|
|
|
|
def make_cron_expr(cron_time: datetime.datetime):
|
|
|
|
return '{min} {hour} {day} {month} * {sec}'.format(
|
|
|
|
min=cron_time.minute,
|
|
|
|
hour=cron_time.hour,
|
|
|
|
day=cron_time.day,
|
|
|
|
month=cron_time.month,
|
|
|
|
sec=cron_time.second,
|
|
|
|
)
|
|
|
|
|
2021-03-09 00:18:33 +01:00
|
|
|
|
|
|
|
# Prepare a cronjob that should start test_timeout/2 seconds from the application start
|
2022-04-28 00:57:49 +02:00
|
|
|
cron_time = datetime.datetime.now() + datetime.timedelta(seconds=test_timeout / 2)
|
2021-03-09 00:18:33 +01:00
|
|
|
|
|
|
|
|
2022-04-28 00:57:49 +02:00
|
|
|
@cron(make_cron_expr(cron_time))
|
2021-03-09 00:18:33 +01:00
|
|
|
def cron_test(**_):
|
2022-04-28 00:57:49 +02:00
|
|
|
cron_queue.put('cron_test')
|
|
|
|
|
|
|
|
|
|
|
|
# Prepare another cronjob that should start 1hr + test_timeout/2 seconds from the application start
|
|
|
|
cron_time = datetime.datetime.now() + datetime.timedelta(
|
|
|
|
hours=1, seconds=test_timeout / 2
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@cron(make_cron_expr(cron_time))
|
|
|
|
def cron_1hr_test(**_):
|
|
|
|
cron_queue.put('cron_1hr_test')
|