Skip to content

Commit

Permalink
Add Job last modified
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Mar 6, 2024
1 parent 7c0470f commit 3c94c17
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Sources/HummingbirdJobsPostgres/CreateJobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct CreateJobQueue: HBPostgresMigration {
CREATE TABLE IF NOT EXISTS _hb_jobs (
id uuid PRIMARY KEY,
job json,
status smallint
status smallint,
lastModified TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
)
""",
logger: logger
Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdJobsPostgres/PostgresJobsQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public final class HBPostgresQueue: HBJobQueueDriver {

func setStatus(jobId: JobID, status: Status, connection: PostgresConnection) async throws {
try await connection.query(
"UPDATE _hb_jobs SET status = \(status) WHERE id = \(jobId)",
"UPDATE _hb_jobs SET status = \(status), lastModified = \(Date.now) WHERE id = \(jobId)",
logger: self.logger
)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/HummingbirdPostgresTests/JobsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ final class JobsTests: XCTestCase {
try await jobQueue.push(id: jobIdentifer, parameters: 0)
await self.wait(for: [expectation], timeout: 5)

let failedJobs = try await jobQueue.queue.getJobs(withStatus: .processing)
XCTAssertEqual(failedJobs.count, 1)
let processingJobs = try await jobQueue.queue.getJobs(withStatus: .processing)
XCTAssertEqual(processingJobs.count, 1)
let pendingJobs = try await jobQueue.queue.getJobs(withStatus: .pending)
XCTAssertEqual(pendingJobs.count, 0)
return jobQueue
Expand Down

0 comments on commit 3c94c17

Please sign in to comment.