Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add scheduled job execution with runAt field #2017

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Guide/jobs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ 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:
rvarun11 marked this conversation as resolved.
Show resolved Hide resolved

```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
rvarun11 marked this conversation as resolved.
Show resolved Hide resolved
```

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.
rvarun11 marked this conversation as resolved.
Show resolved Hide resolved

This can be done in a controller action or in a script as will be shown below.

Expand Down