Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Job every 4 days but first run should happen now

Tags:

apscheduler

I am trying to setup APScheduler to run every 4 days, but I need the job to start running now. I tried using interval trigger but I discovered it waits the specified period before running. Also I tried using cron the following way:

sched = BlockingScheduler()
sched.add_executor('processpool')

@sched.scheduled_job('cron', day='*/4')
def test():
    print('running')

One final idea I got was using a start_date in the past:

@sched.scheduled_job('interval', seconds=10, start_date=datetime.datetime.now() - datetime.timedelta(hours=4))

but that still waits 10 seconds before running.

like image 546
PepperoniPizza Avatar asked Jan 28 '18 13:01

PepperoniPizza


People also ask

Is there a way to run the same job 4 times?

Is there a way to run the same job 4 times with 1 task? If yes, how do I configure that. Show activity on this post. (I'll assume you are using Win 7). In the Create Task dialog, click the Triggers tab. Then click the New button. In the New Trigger dialog, you will see an Advanced Settings section. It has a Repeat Task area.

How do I know how long a job run has been?

The height of the individual job run and task run bars provides a visual indication of the run duration. Azure Databricks maintains a history of your job runs for up to 60 days. If you need to preserve job runs, Databricks recommends that you export results before they expire. For more information, see Export job run results.

How many days a week should you run?

Many running experts recommend running no more than four days a week. "Running is a single-leg sport," Tavel says. "You leap and land on one leg at a time." That takes balance. When you're running, you're using your core, back and leg muscles to stay upright.

How do I Run my jobs?

You can run your jobs immediately or periodically through an easy-to-use scheduling system. You can implement a task in a JAR, an Azure Databricks notebook, a Delta Live Tables pipeline, or an application written in Scala, Java, or Python.


2 Answers

Try this instead:

@sched.scheduled_job('interval', days=4, next_run_time=datetime.datetime.now())
like image 82
Alex Grönholm Avatar answered Sep 19 '22 04:09

Alex Grönholm


Similar to the above answer, only difference being it uses add_job method.

scheduler = BlockingScheduler()
scheduler.add_job(dump_data, trigger='interval', days=21,next_run_time=datetime.datetime.now())
like image 33
Yogesh Kate Avatar answered Sep 23 '22 04:09

Yogesh Kate