Create one-time cronjobs
If you would like to set up a one-time cronjob, i.e. cronjob that runs at a specific time once and never repeats, you can follow these instructions:
- Click Add a cron job or Edit existing cronjob
- Enter the URL to your cron script.
- Enter desired time into the Time Pattern field, e.g. Feb 14, 2019, 7:30
- Make sure you select the correct Timezone
- Click Save changes.
And that's it. You can click on the time pattern field e.g. Feb 14, 2019, 7:30 in the example above, and it'll show the next execution time so you can confirm the time settings are correct.
Auto delete stopped one-time cronjobs
To automatically delete one-time cronjobs after their executions, create a group and select Delete stopped cronjobs after with an appropriate value e.g. 3 days.
Then create all cronjobs under that groups.
Programmatically create one-time cronjobs using our API
Create a group
curl -X POST "https://www.fastcron.com/api/v1/group_add" \
-H 'Content-Type: application/json' \
-d '{"token":"YOUR_API_TOKEN", "name": "one-time", "autoDelete": 3}'
This will create a group named "one-time" that automatically deletes its stopped cronjobs after 3 days.
It will output something like this:
{"status":"success","code":0,"data":{"id":183773,"name":"one-time","autoDelete":3,"jobCount":0,"contacts":[]}}
which shows the group ID is 183773
Create multiple cronjobs in that group
curl -X POST "https://www.fastcron.com/api/v1/cron_batch_add" \
-H 'Content-Type: application/json' \
-d '{"token":"YOUR_API_TOKEN", "data":[{"url":"https://example.com", "expression":"May 20, 2023, 8:00", "group": 183773},{"url":"https://example.com", "expression":"May 20, 2023, 9:00", "group": 183773}]}'
This will create two cronjobs under the groups 183773
Edit all cronjobs in that group
curl -X POST "https://www.fastcron.com/api/v1/cron_group_edit" \
-H 'Content-Type: application/json' \
-d '{"token":"YOUR_API_TOKEN", "id": 183773, "timezone": "UTC"}'
This will update all cronjobs under the group 183773
to timezone UTC.
Delete that group and all cronjobs in it
curl -X POST "https://www.fastcron.com/api/v1/group_vanish" \
-H 'Content-Type: application/json' \
-d '{"token":"YOUR_API_TOKEN", "id": 183773}'
Comments
4 comments
awesome
Can this be done, but from the API (cron.add) ???
Can this be done, but from the API (cron.add) ???
Same question here!
And a new one: It is possible that one time cron jobs will automatically delete after execution?
Thanks!
Sorry for being late.
Yes, you can use cron.add API function and set the expression like this
https://www.setcronjob.com/api/cron.add?token=***&url=example.com/cron&expression=Sep 20, 2019, 8:30
For automatically deleting one-time cronjobs, see
https://blog.setcronjob.com/2018/09/auto-delete-one-time-cronjobs.html
I hope this helps.
Please sign in to leave a comment.