Reputation: 1028
I would like to create a cron job in GAE but I do not want it to be scheduled. I would like to call it manually whenever I need it.
What should I put in the schedule element?
Upvotes: 3
Views: 2029
Reputation: 1076
You can also do something like
schedule: every 99999 hours
That way, its almost like 11 years so you know that cron won't be triggered till then.
Upvotes: 3
Reputation: 695
Before reading, this is slightly hacky although it does work.
I needed something similar to this, primarily due to the need for a slightly longer processing time than 60 seconds.
In my cron.yaml
I specified:
- description: My example cron
url: /cron/my/example/cron
schedule: 25 of dec 12:00
Then within my handler I check if the date is the 25th december and abandon the request.
This seems to be the only way to have a 'manual' cron.
In Python this is simple to check the date.
from datetime import datetime
import logging
now = datetime.utcnow()
if now.day == 25 and now.month == 12:
logging.info("Skipping as it's the 25th December")
return
Upvotes: 1
Reputation: 39814
From Scheduling Tasks With Cron for Python:
A cron job makes an HTTP GET request to a URL as scheduled. The handler for that URL executes the logic when it is called.
So, as @snakecharmerb mentioned, you have to create that handler doing whatever you want the cron job to do and map it to the desired cron url.
In order to avoid scheduling you simply don't upload the cron configuration, instead you manually trigger the job by making that same GET request that the scheduler would otherwise do, for example using curl
:
curl https://your_app.appspot.com/cron_handler_url
Upvotes: 4