Skip to content

Commit

Permalink
docs: add scheduled job execution with runAt field (#2017)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rvarun11 authored Dec 3, 2024
1 parent 6f2ed28 commit 0ac5d13
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Guide/jobs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,25 @@ 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 (as soon as a job worker is available):

```haskell
newRecord @EmailCustomersJob |> create
```
2. Schedule for future execution:

```haskell
import Data.Time.Clock (addUTCTime, getCurrentTime, nominalDay)

now <- getCurrentTime
newRecord @EmailCustomersJob
|> set #runAt (addUTCTime nominalDay 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.

Expand Down

0 comments on commit 0ac5d13

Please sign in to comment.