Skip to content

Commit e9655b2

Browse files
thoven87adam-fowler
authored andcommitted
Adding job pruner and instruction on how to register and run the job on a schedule
1 parent d12158b commit e9655b2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Sources/JobsPostgres/JobPruner.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Hummingbird server framework project
4+
//
5+
// Copyright (c) 2025 the Hummingbird authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Jobs
16+
17+
public struct JobPruner: JobParameters {
18+
static public var jobName: String { "JobPruner" }
19+
}

Sources/JobsPostgres/PostgresJobsQueue.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
468468
logger: self.logger
469469
)
470470
}
471-
/// Helper func which to be use by a scheduled jobs
472-
/// for performing job clean up based on a given set of policies
471+
472+
/// This menthod shall be called with the JobPruner after registration as follow
473+
/// someJobQueue.registerJobparameters: JobPruner.self) { _, _ in
474+
/// try await someJobQueue.processDataRetentionPolicy()
475+
/// }
476+
/// let jobScheddule = JobSchedule([ .init(job: JobPruner(), schedule: .everyHour()) ])
473477
public func processDataRetentionPolicy() async throws {
474478
try await self.client.withTransaction(logger: logger) { tx in
475479
let now = Date.now.timeIntervalSince1970

0 commit comments

Comments
 (0)