-
-
Notifications
You must be signed in to change notification settings - Fork 1
Jobs retention #29
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
Closed
Closed
Jobs retention #29
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
969987a
Job retention
thoven87 5b9a1ad
Job retention
thoven87 a3a3691
Swift format
thoven87 3d5352f
Addressing PR comments
thoven87 7b5fae1
Update PostgresJobsQueue.swift
thoven87 5a36adb
fixing the failing test
thoven87 2730cbb
Merge branch 'main' into jobs-retention
thoven87 b39f0b0
Adding job pruner and instruction on how to register and run the job …
thoven87 9442322
increase time amount for test job
thoven87 9510a66
Update JobsTests.swift
thoven87 33bc4e4
Update JobsTests.swift
thoven87 028c281
up concurrency to 3 to match number of job. There seems to be a timin…
thoven87 be47d21
Wait for 200 milliseconds before checking the job count.
thoven87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2025 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
|
||
/// Data rentension policy | ||
public struct RetentionPolicy: Sendable { | ||
|
||
/// Data retention policy | ||
public struct RetainData: Equatable, Sendable { | ||
enum Policy { | ||
case retain(for: TimeInterval) | ||
case doNotRetain | ||
} | ||
|
||
let rawValue: Policy | ||
/// Retain policy | ||
/// default to 7 days | ||
public static func retain(for timeAmout: TimeInterval = 60 * 60 * 24 * 7) -> RetainData { | ||
RetainData(rawValue: .retain(for: timeAmout)) | ||
} | ||
/// Never retain any data | ||
public static let never: RetainData = RetainData(rawValue: .doNotRetain) | ||
|
||
public static func == (lhs: RetentionPolicy.RetainData, rhs: RetentionPolicy.RetainData) -> Bool { | ||
switch (lhs.rawValue, rhs.rawValue) { | ||
case (.retain(let lhsTimeAmout), .retain(let rhsTimeAmout)): | ||
return lhsTimeAmout == rhsTimeAmout | ||
case (.doNotRetain, .doNotRetain): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} | ||
|
||
/// Jobs with status cancelled | ||
/// default retention is set for 7 days | ||
public var cancelled: RetainData | ||
/// Jobs with status completed | ||
/// default retention is set to 7 days | ||
public var completed: RetainData | ||
/// Jobs with status failed | ||
/// default retention is set to 30 days | ||
public var failed: RetainData | ||
|
||
public init( | ||
cancelled: RetainData = .retain(), | ||
completed: RetainData = .retain(), | ||
failed: RetainData = .retain(for: 60 * 60 * 24 * 30) | ||
) { | ||
self.cancelled = cancelled | ||
self.completed = completed | ||
self.failed = failed | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we are expecting people to set up a Job to call this, why don't we provide them with one.