Exemplo n.º 1
0
def get_periodic_tasks_info():
    from celery import current_app
    schedule = Service(current_app).get_scheduler().get_schedule()
    tasks = []
    for key, entry in schedule.items():
        # entry.is_due() returns (is_due, time_in_seconds_for_next_execution)
        is_due_tpl = entry.is_due()

        next_execution = timezone.now() + datetime.timedelta(
            seconds=is_due_tpl[1])

        # remove delay between the timezone.now and the schedule entry due date
        next_execution = next_execution.replace(microsecond=0)

        tasks.append({
            'name':
            key,
            'task':
            entry.task,
            'args':
            '(' + ', '.join([json.dumps(arg) for arg in entry.args]) + ')',
            'kwargs':
            json.dumps(entry.kwargs),
            'is_due':
            is_due_tpl[0],
            'next_execution':
            next_execution
        })

    return tasks
Exemplo n.º 2
0
from datetime import datetime, timedelta
from celery.beat import Service
from tardis.celery import tardis_app

schedule = Service(tardis_app).get_scheduler().get_schedule()
now = datetime.utcnow()

for task_name, task in schedule.items():
    next_run = task.last_run_at.replace(tzinfo=None) + task.schedule.run_every
    print("{}: check if {} is less than {}".format(task_name, now, next_run))
    assert now < next_run