joyz joyz - 1 year ago 101
Python Question

How to set a cron job on Skygear to run every 12 hours?

Trying to set a cron job on my Skygear python cloud code, but not sure what I should enter in the decorator. I only know that it will work for units in second, but how to schedule a job to run every 12 hours? It is hard to calculate the seconds every time.

My code is like this, the function is to call a POST request:

@skygear.every('@every 43200s')
def post_req():
print ('scheduled to run every 12 hours')
url = myurl
ref = something
r =, data = {'token':some_token, 'ref':something})

It actually works but is there some ways to write in a better format?

Answer Source

It seems like skygear.every also accepts crontab notation… so 0 */12 * * * could also do the trick.

Edit: Reading the robfig/cron docs, the best solution would actually be just @every 12h

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download