Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run a cron every 5 seconds, when job_id is set? (does the minimum have to be 60 seconds?) #459

Open
epicwhale opened this issue May 19, 2024 · 0 comments

Comments

@epicwhale
Copy link

I need to run a cron in my worker every 5 seconds, but I also want to provide it a job_id so there's no duplicates running in parallel. The next cron task for the job should only run if the previous one is completed.

My cron definition:

    cron(
        my_task,
        unique=True,
        job_id="cron_my_task",  # to prevent duplicate task runs
        second=set(range(0, 60, 5)),         # every 5 seconds
        keep_result=0, 
        max_tries=1,
    ),

But when I configure a worker with this, I notice there's an in-progress entry created with a TTL of 60 seconds, which prevents any future cron runs from running till it expires, even if my tasks is completed in a few seconds.

Am I missing something important here? As this behavior feels rather unpredictable, and undocumented.

Digging deeper into the code, I see there's a
keep_cronjob_progress = 60 <--- # how long to keep the "in_progress" key after a cron job ends to prevent the job duplication which is a constant that can't be modified:

keep_cronjob_progress = 60

What's the recommended way to accomplish my requirement of running a task every 5 seconds, provided the previous cron run of that task is completed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant