question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some problems with creating a scheduled task to run only once

See original GitHub issue

My goal is to create a scheduled task to run only once on a specified date, on the first try, it seemed good until my schedule got repeated.

So, I read about repeats As the docs pointed, the default value for repeats is -1 which means always, so I set it to 0 as it means never so, my schedule never repeats and only run once.

Here is an example of what I did

schedule('app.tasks.auto_subscription_renew',
                     amount_cents, currency, instance.profile.id,name=schedule_name,repeats=0, schedule_type=Schedule.ONCE, next_run=end_date)

The problem is, when set to 0, the scheduler never run. Then I find this hint about Schedule.ONCE

So, I tried another value like -5, nothing changes, the same behaviour as -1

Also, what about the issue of multiple workers to catch the same task and run it twice? I had set it to 8 workers before but changed this to 1

Here is my conf, and for cache, I didn’t set up one, the default in-memory cache in Django is being used for sure.

Q_CLUSTER = {
    'name': '_tasks',
    'workers': 1,
    'daemonize_workers': False,
    'retry': 3600,
    'compress': True,
    'save_limit': 0,
    'orm': 'temp',
    'bulk': 20
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Koed00commented, Sep 29, 2020

Ok I understand the problem now; one of the contributros added the option to have the queue on a different database, but it was never intended to run everything, including the admin and schedule stuff, on a separate db connection. There is another issue on this somehwere, but I can’t quite find it right now.

We would have to the option to run everything on a different db for your setup to completely work. Which I’m all for. A quick workaround could be to add the schedule object (and other objects) to a database router and let django know where to find them by default.

1reaction
mohmyocommented, Sep 29, 2020

Thank you so much, I have a better understanding for this now, but I feel there are plenty of points that should be added to the documentation to make it more clear and stop confusion because I only followed it and got to the current situation.

Now, I will compare between running on the default for now and switch to a separate later when it’s complete, or do the workaround you mentioned, it depends on the scale I’m expecting, so I should reconsider this again.

Thanks again for your help and your effort to make this package great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task scheduler - Windows 2019 - Indefinitly task not running
I found if I selected Indefinitely the task will not run. Once I selected Weekly and everyday of Day of the week and...
Read more >
Task only runs once in Task Scheduler when trigger the task ...
I want to run a console application 'Download.exe' every 5 minutes. There is no problem in the Exe file I've created. The execution...
Read more >
Task Scheduler repeat task not triggering - Super User
It seems that repeated tasks are not executed when run manually (right click on a task and then select "Run"). When run manually,...
Read more >
Why is Windows Task Scheduler trying to launch multiple ...
The task properties still shows only one trigger, but you can see that the task is triggered multiple times simultaneously in the task...
Read more >
Scheduled Tasks running forever, randomly, or multiple times
One of the suggestions was to switch to daily recurrence from weekly for repeating tasks. So instead of setting up weekly tasks, switch...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found