I want to run a cron job for every 5 mins only on a particular day of the week. I am using python schedule library and I can do these jobs individually. But how do I club them?
code
import schedule
def check():
print('Checking')
schedule.every(10).monday.do(check)
while True:
# Checks whether a scheduled task is pending to run or not
schedule.run_pending()
This gives an error IntervalError: Use mondays instead of monday
when I try with mondays, I get an error AttributeError: 'Job' object has no attribute 'mondays'
can someone help me with this.
I don't think the schedule
package supports combinations of different time units the way you want. You can achieve what you want doing something like:
import schedule
import time
import datetime
def job():
if datetime.datetime.today().weekday() == 0:
print("I'm working...")
schedule.every(5).minutes.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Maybe not the most elegant solution, though.
Did you try with "time"?
import time
...
schedule.every().monday.do(job)
while True:
schedule.run_pending()
time.sleep(300)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.