Quickstart: create and run a job
Create a job that calls your app every day, run it straight away, and read what happened.
This quickstart creates a job that calls your app every day at 2:00 in Dar es Salaam, runs it once straight away, and reads the result.
Before you begin
- Set up your environment, so
SCHEDULER_TOKENandPROJECT_IDare set. - Have an HTTPS address in your app that answers
POSTrequests with a 2xx status. This quickstart useshttps://mail.example.com/tasks/report.
Create and run a job
Create the job
curl -X POST "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs" \ -H "Authorization: Bearer $SCHEDULER_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "Nightly report", "schedule": "0 2 * * *", "timeZone": "Africa/Dar_es_Salaam", "target": { "url": "https://mail.example.com/tasks/report", "method": "POST" } }'The answer holds the new job. Copy its
idinto a variable:export JOB_ID="the-job-id"Its
nextRunAtsays when it runs next.Run it now
You do not have to wait for the schedule:
curl -X POST "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID/run" \ -H "Authorization: Bearer $SCHEDULER_TOKEN"The answer is the new run, with
triggerset tomanual. In the console, you can do the same with Run now on the job’s page.Read the result
List the job’s runs. The newest is first:
curl "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID/runs" \ -H "Authorization: Bearer $SCHEDULER_TOKEN"When your app answered with a 2xx status, the run’s
statusissucceeded. If it isfailed,lastErrorClassandlastErrorsay why. See View runs.
Clean up
Delete the job if you do not want it to keep running. This deletes its runs too, and cannot be undone:
curl -X DELETE "https://scheduler-api.digitospace.com/v1/projects/$PROJECT_ID/jobs/$JOB_ID" \
-H "Authorization: Bearer $SCHEDULER_TOKEN"What’s next
- Verify calls to your target, so your app accepts calls only from the scheduler.
- Retry jobs that fail.
- Configure job schedules in cron format.
Last updated