Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 47 additions & 0 deletions Hummingbird.docc/JobsPostgres/JobsPostgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,53 @@ try await jobQueue.pause(jobID: jobID)
try await jobQueue.resume(jobID: jobID)
```

### Job Retention

When initializing the job queue you can set you can set what the queue should do with failed, cancelled and completed jobs.

```swift
let jobQueue = JobQueue(
.postgres(
client: postgresClient,
migrations: postgresMigrations,
configuration: .init(
retentionPolicy: .init(
cancelled: .doNotRetain, completed: .retain, failed: .retain
)
),
logger: logger
),
...
```

If you don't set the retention policy the default is to retain failed jobs, but delete both cancelled and completed jobs.

### Job Cleanup

The postgres job queue driver includes the function ``PostgresJobQueue/cleanup(failedJobs:processingJobs:pendingJobs:completedJobs:cancelledJobs:logger:)`` to do large scale cleanup of the job queue. This allows you to remove or add jobs back onto the pending queue based on their current state eg the code below will add the failed jobs back onto the pending queue and deletes any completed jobs older than 7 days.

```swift
try await jobQueue.queue.cleanup(
failedJobs: .rerun,
completedJobs: .remove(maxAge: .seconds(60*60*24*7))
)
```

The cleanup allows you to edit the status of jobs in the `pending` and `processing` state. This should be done with care though. Don't do this while a queue handler is processing the queue as this will have undefined results.

If you are retaining completed or cancelled jobs you most likely don't want to keep them forever. The postgres job queue provides a cleanup job you can use alongside the job scheduler to remove old jobs at regular intervals.

```swift
var jobSchedule = JobSchedule()
jobSchedule.addJob(
jobQueue.queue.cleanupJob,
parameters: .init(completedJobs: .remove(maxAge: 60*60*24*7)),
schedule: .weekly(day: .sunday, hour: 1)
)
```

Read more about the job scheduler in the <doc:JobsGuide#Job-Scheduler> section of the Jobs guide.

## Topics

### Job Queue
Expand Down
47 changes: 47 additions & 0 deletions Hummingbird.docc/JobsRedis/JobsRedis.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ try await jobQueue.pause(jobID: jobID)
try await jobQueue.resume(jobID: jobID)
```

### Job Retention

When initializing the job queue you can set you can set what the queue should do with failed, cancelled and completed jobs.

```swift
let jobQueue = JobQueue(
.redis(
redisService.pool,
configuration: .init(
retentionPolicy: .init(
cancelled: .doNotRetain, completed: .retain, failed: .retain
)
),
logger: logger
),
...
```

If you don't set the retention policy the default is to retain failed jobs, but delete both cancelled and completed jobs.

### Job Cleanup

The redis job queue driver includes the function ``RedisJobQueue/cleanup(failedJobs:processingJobs:pendingJobs:cancelledJobs:completedJobs:)`` to do large scale cleanup of the job queue. This allows you to remove jobs or add them back onto the pending queue based on their current state eg the code below will add the failed jobs back onto the pending queue and deletes any completed jobs older than 7 days.

```swift
try await jobQueue.queue.cleanup(
failedJobs: .rerun,
completedJobs: .remove(maxAge: .seconds(60*60*24*7))
)
```

The cleanup allows you to edit the status of jobs in the `pending` and `processing` state. This should be done with care though. Don't do this while a queue handler is processing the queue as this will have undefined results.

If you are retaining completed or cancelled jobs you most likely don't want to keep them forever. The redis job queue provides a cleanup job you can use alongside the job scheduler to remove old jobs at regular intervals.

```swift
var jobSchedule = JobSchedule()
jobSchedule.addJob(
jobQueue.queue.cleanupJob,
parameters: .init(completedJobs: .remove(maxAge: 60*60*24*7)),
schedule: .weekly(day: .sunday, hour: 1)
)
```

Read more about the job scheduler in the <doc:JobsGuide#Job-Scheduler> section of the Jobs guide.


## Topics

### Job Queue
Expand Down
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.6.1"),
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.14.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-auth.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-compression.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-fluent.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.8"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-postgres.git", from: "1.0.0-beta.2"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-redis.git", revision: "bdb42b1ca7499818bb3798f1005880ff77da5ab2"),
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", branch: "main"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-postgres.git", branch: "main"),
.package(url: "https://github.com/hummingbird-project/swift-jobs-redis.git", branch: "main"),
.package(url: "https://github.com/hummingbird-project/hummingbird-lambda.git", from: "2.0.0-rc.3"),
.package(url: "https://github.com/hummingbird-project/swift-mustache.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-postgres.git", branch: "0.8.0"),
.package(url: "https://github.com/hummingbird-project/postgres-migrations.git", from: "0.1.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-redis.git", from: "2.0.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "2.2.0"),
.package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "2.5.0"),
.package(url: "https://github.com/hummingbird-project/swift-websocket.git", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
Expand Down