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

Every minute on the minute #163

Open
claygorman opened this issue Sep 21, 2017 · 6 comments
Open

Every minute on the minute #163

claygorman opened this issue Sep 21, 2017 · 6 comments

Comments

@claygorman
Copy link

Hello,

I am not seeing a way to do it on the minute every minute. Is there a way to do that?

* * * * * is the cron equivilent

@PvtHaggard
Copy link

PvtHaggard commented Oct 5, 2017

import schedule
import time

def job():
    print("Running job: " + time.asctime())

def wait():
    while int(time.time()) % 60 != 0:
        pass
    print("End wait: {}".format(time.asctime()))

wait()
schedule.every(1).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

This will do what you are wanting. wait() simply stalls the program until the time is 0 seconds and then goes on to schedules the jobs.

The output from the short time I was running it.

End wait: Fri Oct  6 03:13:00 2017
Running job: Fri Oct  6 03:14:00 2017
Running job: Fri Oct  6 03:15:00 2017
Running job: Fri Oct  6 03:16:00 2017
Running job: Fri Oct  6 03:17:00 2017
Running job: Fri Oct  6 03:18:00 2017

@rokcarl
Copy link

rokcarl commented Jul 9, 2018

This doesn't work for real life circumstances. As soon as you start adding delays (e.g. time.sleep(7) inside the job() function) to simulate real life activity (database access, 3rd party services), this doesn't run on the minute (0 seconds) anymore:

End wait: Mon Jul  9 16:28:00 2018
Running job: Mon Jul  9 16:29:00 2018
Running job: Mon Jul  9 16:30:07 2018

@chinkan
Copy link

chinkan commented Jul 22, 2018

Hi, I have similar issue here. I just set a scheduler run by every minute. Here is the result

scheduler run... 2018-07-22 13:20:00.559519
scheduler run... 2018-07-22 13:21:00.632520
scheduler run... 2018-07-22 13:22:00.704910
scheduler run... 2018-07-22 13:23:00.778596
scheduler run... 2018-07-22 13:24:00.852522
scheduler run... 2018-07-22 13:25:00.923478
scheduler run... 2018-07-22 13:26:00.995238
scheduler run... 2018-07-22 13:27:01.065289 <--------------
scheduler run... 2018-07-22 13:28:01.137599
scheduler run... 2018-07-22 13:29:01.209585
...
...
scheduler run... 2018-07-22 15:28:09.683525 <--------------

after run it some time, the schedule job is not fire on 00 second.
how can I make it keep run on every xx:00 without delay? Thanks!

Here is my testing code

import time
import schedule
import datetime

def startScheduler():
    now = datetime.datetime.now()
    delay = 60 - now.second
    time.sleep(delay)
    schedule.every(1).minutes.do(run)
    while 1:
        schedule.run_pending()
        time.sleep(1)

def run():
    now = datetime.datetime.now()
    print("scheduler run...", now)

startScheduler()

@chinkan
Copy link

chinkan commented Jul 23, 2018

After keep run it overnight, it totally delay to 42 sec
scheduler run... 2018-07-23 09:55:42.276265
How can I ensure the job will fire only on 00 second every minutes? Thanks!

@fhchl
Copy link

fhchl commented Nov 21, 2018

This seems to come from these lines, where the next run is scheduled after the current job is run on the basis of the job-interval time and the current time.

I would also love the functionality of precise scheduling using the interval syntax, but this does not seem to be a priority of this library. Even if one would exchange the call to job_func and schedule_next_run, the run times will drift as the scheduling is happening with relative and not absolute timings.

@WoLfulus
Copy link
Contributor

Start a thread (and don't wait for it) on the job function, so it won't block the scheduler thread.
But be aware that depending on how much time the job takes to finish, you'll see jobs running concurrently and you'll need to manage race conditions.

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

6 participants