Skip to content

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
wants to merge 13 commits into from
Closed

Conversation

thoven87
Copy link
Contributor

  • Adding job retention configuration
  • Make job priority static vars instead of static func

Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments

@adam-fowler
Copy link
Member

adam-fowler commented Mar 19, 2025

Sorry I'm wondering if we do this another way. Basically the retention policy is retain or not, without a timeout. Then we add a function for users to call.

func purgeRetainedJobsEarlierThan(cancelled: Date, finished: Date, failed: Date) {

Actually you could just update the cleanup function.

Then users could add their own scheduled job. We could even write the job for them

struct PurgeOldJobs: JobParameters {
    let jobQueue: JobQueue<PostgresJobQueue>
}

jobQueue.registerJob(parameters: PurgeOldJobs.self) { parameters,_ in
    parameters.jobQueue.cleanUp(
        cancelledJobs: .remove(olderThan: .now - 4*24*60*60),
        finishedJobs: .remove(olderThan: .now - 7*24*60*60)
    )
}

jobSchedule = JobSchedule(job: PurgeOldJobs.self, .onMinutes(0,10,20,30,40,50))

I know this ends up being more work for the user, but it makes it a lot more configurable

@thoven87
Copy link
Contributor Author

Sorry I'm wondering if we do this another way. Basically the retention policy is retain or not, without a timeout. Then we add a function for users to call.

func purgeRetainedJobsEarlierThan(cancelled: Date, finished: Date, failed: Date) {

Actually you could just update the cleanup function.

Then users could add their own scheduled job. We could even write the job for them

struct PurgeOldJobs: JobParameters {
    let jobQueue: JobQueue<PostgresJobQueue>
}

jobQueue.registerJob(parameters: PurgeOldJobs.self) { parameters,_ in
    parameters.jobQueue.cleanUp(
        cancelledJobs: .remove(olderThan: .now - 4*24*60*60),
        finishedJobs: .remove(olderThan: .now - 7*24*60*60)
    )
}

jobSchedule = JobSchedule(job: PurgeOldJobs.self, .onMinutes(0,10,20,30,40,50))

I know this ends up being more work for the user, but it makes it a lot more configurable

I think this works better and also maybe introduce a job rescue (orphan jobs :))?

Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you want to keep this separate from cleanup function. Also making the retain times parameters of the function instead of static data might make it flexible.

func updateJob(id: JobID, buffer: ByteBuffer, connection: PostgresConnection) async throws {
/// Helper func which to be use by a scheduled jobs
/// for performing job clean up based on a given set of policies
public func processDataRetentionPolicy() async throws {
Copy link
Member

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.

@thoven87
Copy link
Contributor Author

thoven87 commented May 2, 2025

Any reason you want to keep this separate from cleanup function. Also making the retain times parameters of the function instead of static data might make it flexible.

The notification from yesterday was because I merged the main branch into this branch. I have a few meetings today and should have the updated logic in by this weekend.

@thoven87
Copy link
Contributor Author

Sorry I'm wondering if we do this another way. Basically the retention policy is retain or not, without a timeout. Then we add a function for users to call.

func purgeRetainedJobsEarlierThan(cancelled: Date, finished: Date, failed: Date) {

Actually you could just update the cleanup function.
Then users could add their own scheduled job. We could even write the job for them

struct PurgeOldJobs: JobParameters {
    let jobQueue: JobQueue<PostgresJobQueue>
}

jobQueue.registerJob(parameters: PurgeOldJobs.self) { parameters,_ in
    parameters.jobQueue.cleanUp(
        cancelledJobs: .remove(olderThan: .now - 4*24*60*60),
        finishedJobs: .remove(olderThan: .now - 7*24*60*60)
    )
}

jobSchedule = JobSchedule(job: PurgeOldJobs.self, .onMinutes(0,10,20,30,40,50))

I know this ends up being more work for the user, but it makes it a lot more configurable

I think this works better and also maybe introduce a job rescue (orphan jobs :))?

I have thought of this implementation for a while, implementing as suggested will require JobQueue to conform to Codable. Is it a good idea to do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants