From fdfb6a975ad25bebcae0669ef133bda04bde30fa Mon Sep 17 00:00:00 2001 From: Varun Rajput Date: Mon, 2 Dec 2024 15:12:34 +0530 Subject: [PATCH] docs: add scheduled job execution with runAt field Add documentation for scheduling future job execution using the runAt field. Reorganize job execution docs to clearly distinguish between immediate and scheduled runs. Note polling interval for scheduled jobs. --- Guide/jobs.markdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Guide/jobs.markdown b/Guide/jobs.markdown index 511ebc595..15b126e61 100644 --- a/Guide/jobs.markdown +++ b/Guide/jobs.markdown @@ -44,11 +44,22 @@ instance Job EmailCustomersJob where ### Running the job -IHP watches the job table in the database for any new records and automatically runs the job asynchronously when a new job is added. So to run a job, simply create a new record: +IHP watches the job table in the database for any new records and automatically runs the job asynchronously when a new job is added. There are two ways to run a job: + +1. Run immediately: ```haskell newRecord @EmailCustomersJob |> create ``` +2. Schedule for future execution: + +```haskell +now <- getCurrentTime +newRecord @EmailCustomersJob + |> set #runAt (addUTCTime 86400 now) -- Schedule 24 hours in the future + |> create +``` +The `runAt` field determines when the job should be executed. If not set, the job runs immediately. When set, IHP polls for scheduled jobs approximately every minute and executes any jobs whose runAt time has passed. This can be done in a controller action or in a script as will be shown below.