Skip to content

Commit 204ccf8

Browse files
committed
Add logging to debug stalled database records
1 parent a643cc7 commit 204ccf8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

Sources/QueuesDatabaseHooks/QueuesDatabaseNotificationHook.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct QueuesDatabaseNotificationHook: JobEventDelegate {
3939
/// - eventLoop: The eventLoop
4040
public func dispatched(job: JobEventData, eventLoop: EventLoop) -> EventLoopFuture<Void> {
4141
let data = payloadClosure(job)
42-
return QueueDatabaseEntry(jobId: data.id,
42+
let model = QueueDatabaseEntry(jobId: data.id,
4343
jobName: data.jobName,
4444
queueName: data.queueName,
4545
payload: Data(data.payload),
@@ -49,33 +49,44 @@ public struct QueuesDatabaseNotificationHook: JobEventDelegate {
4949
dequeuedAt: nil,
5050
completedAt: nil,
5151
errorString: nil,
52-
status: .queued).save(on: database)
52+
status: .queued)
53+
54+
return model.save(on: database).map { _ in
55+
self.database.logger.info("\(job.id) - Added route to database, db ID \(model.id?.uuidString ?? "")")
56+
}
5357
}
5458

5559
/// Called when the job is dequeued
5660
/// - Parameters:
5761
/// - jobId: The id of the Job
5862
/// - eventLoop: The eventLoop
5963
public func didDequeue(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
60-
QueueDatabaseEntry
64+
self.database.logger.info("\(jobId) - Updating to status of running")
65+
return QueueDatabaseEntry
6166
.query(on: database)
6267
.filter(\.$jobId == jobId)
6368
.set(\.$status, to: .running)
6469
.set(\.$dequeuedAt, to: Date())
65-
.update()
70+
.update().map { _ in
71+
self.database.logger.info("\(jobId) - Done updating to status of running")
72+
}
6673
}
6774

6875
/// Called when the job succeeds
6976
/// - Parameters:
7077
/// - jobId: The id of the Job
7178
/// - eventLoop: The eventLoop
7279
public func success(jobId: String, eventLoop: EventLoop) -> EventLoopFuture<Void> {
73-
QueueDatabaseEntry
80+
self.database.logger.info("\(jobId) - Updating to status of success")
81+
82+
return QueueDatabaseEntry
7483
.query(on: database)
7584
.filter(\.$jobId == jobId)
7685
.set(\.$status, to: .success)
7786
.set(\.$completedAt, to: Date())
78-
.update()
87+
.update().map { _ in
88+
self.database.logger.info("\(jobId) - Done updating to status of success")
89+
}
7990
}
8091

8192
/// Called when the job returns an error
@@ -84,12 +95,16 @@ public struct QueuesDatabaseNotificationHook: JobEventDelegate {
8495
/// - error: The error that caused the job to fail
8596
/// - eventLoop: The eventLoop
8697
public func error(jobId: String, error: Error, eventLoop: EventLoop) -> EventLoopFuture<Void> {
87-
QueueDatabaseEntry
98+
self.database.logger.info("\(jobId) - Updating to status of error")
99+
100+
return QueueDatabaseEntry
88101
.query(on: database)
89102
.filter(\.$jobId == jobId)
90103
.set(\.$status, to: .error)
91104
.set(\.$errorString, to: errorClosure(error))
92105
.set(\.$completedAt, to: Date())
93-
.update()
106+
.update().map { _ in
107+
self.database.logger.info("\(jobId) - Done updating to status of error")
108+
}
94109
}
95110
}

0 commit comments

Comments
 (0)