How does a background job work?
- A
POSTorPATCHrequest starts the job and returns right away with an ID. - The job runs in the background.
- You find out it finished in one of two ways:
- Polling: your server checks the job’s status every few seconds. See Poll for results.
- Webhooks: CrazyGoldFish calls your server as soon as the job finishes. See Receive webhooks.
- You fetch the result with a
GETrequest.
Job status values
Partial means the plan was built, but some questions failed. Treat it as a result worth showing, not an error.
Poll for results
- Poll every 5 seconds. Faster polling doesn’t make jobs finish sooner.
- Expect a short
404at the start. Right after you start a Lesson Plan or Worksheet job, itsGETendpoint returns404with astep not foundmessage until a worker picks the job up. Keep polling. - A failed job usually returns
400, with"status": "Failed"and amsgexplaining why. Action Plans, ClassTrack, and Get lesson plan content return200with"status": "Failed"instead, so checkstatuson every200too. - Set a timeout. Some failures leave a job
In Progress. If a job hasn’t completed after 10 minutes, stop polling, start a new job, and contact CrazyGoldFish with the job ID.
Receive webhooks
A webhook is a message CrazyGoldFish sends to your server when a job completes or fails, so you don’t need to keep checking. Technically, it’s aPOST request to an HTTPS address you register.
Register a webhook
1
Find the event's template ID
2
Register your endpoint
Send the template Register one webhook for each event you want.
id, your HTTPS URL, and a secret that you generate:endpoint_urlmust start withhttps://. A successful registration returns201.- Each API user can register one webhook per event. A second one returns
400Webhook already exists. - To change the URL, send
PATCH /webhooks/v1/webhook/{id}/. It requiresendpoint_urland replaces the stored one, and if you leave outsecret_hash, the saved secret is removed. Send both fields every time. - There is no endpoint to delete a webhook. Contact CrazyGoldFish to disable one.
- Template IDs differ between environments, so read them from the templates call rather than hardcoding them.
- If registration succeeded and your jobs complete but nothing ever arrives, your API user may not be fully set up for delivery. Contact CrazyGoldFish.
Events
Every event is sent whether the job succeeded or failed. Check
status: Completed or Failed, and also Partial for action plans.
Payloads
Payloads tell you which job finished. They don’t include the result, so fetch it with the endpoint in the table above.exam_id, plus model_answer_sheet_id or ans_sheet_id for those events. Assignment payloads use webhook_name instead of name. Action plan and ClassTrack payloads use the same shape as the Lesson Plan and Worksheet example above: for student_action_plan the id is the answer sheet ID, for teacher_action_plan it is the exam ID, and for class_track_analysis it is the analysis ID. secret_hash is null if you registered the webhook without a secret.
A webhook can only be registered for an event that exists in your account’s template list. If an event in this table is missing from List event templates, contact CrazyGoldFish to have it added.
Handle deliveries
- Verify the sender. Compare
secret_hashwith the secret you registered, and reject the request if they don’t match. - Respond within 5 seconds with a
2xxstatus. Do slow work after you respond. - Keep polling as a fallback. Most events are sent once with no retry.
exam_evaluation_student_answer_sheet_evaluationis retried once after 5 seconds if your endpoint doesn’t return200or201. - Handle duplicates. Because of retries, the same event can arrive twice.