execute(input) job = { id: input.jobId, recipient: input.recipient } async // Each iteration owns and releases its Services before waiting again. timer 2 seconds timeout 2 minutes result = fetchStatus(job.id) if result.done sendCompletion(job.recipient, job.id) stop end end end return { submitted: true } end fetchStatus(jobId) statusService = service "http_job_status" result = statusService.send({ jobId: jobId }) if result.status != 200 fail Unavailable "Job status is unavailable" end return Object.parse(Bytes.decode(result.bytes)) end sendCompletion(recipient, jobId) notifications = service "smtp_notifications" message = notifications.create("Job Completed", "Job " + jobId + " completed.") message.send([{ scope: "to", email: recipient }]) end