Skip to content

Commit 13e97c1

Browse files
committed
Make public function inlinable
1 parent 2933e23 commit 13e97c1

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

Sources/JobsPostgres/PostgresJobsQueue.swift

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
112112
}
113113

114114
/// Job Status
115+
@usableFromInline
115116
enum Status: Int16, PostgresCodable {
116117
case pending = 0
117118
case processing = 1
@@ -124,11 +125,11 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
124125
/// Queue configuration
125126
public struct Configuration: Sendable {
126127
/// Queue poll time to wait if queue empties
127-
let pollTime: Duration
128+
public var pollTime: Duration
128129
/// Which Queue to push jobs into
129-
let queueName: String
130+
public var queueName: String
130131
/// Retention policy for jobs
131-
let retentionPolicy: RetentionPolicy
132+
public var retentionPolicy: RetentionPolicy
132133

133134
/// Initialize configuration
134135
/// - Parameters
@@ -152,6 +153,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
152153
/// Logger used by queue
153154
public let logger: Logger
154155
let migrations: DatabaseMigrations
156+
@usableFromInline
155157
let isStopped: NIOLockedValueBox<Bool>
156158

157159
/// Initialize a PostgresJobQueue
@@ -180,11 +182,12 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
180182
/// - Parameters:
181183
/// - jobID: an existing job
182184
/// - Throws:
185+
@inlinable
183186
public func cancel(jobID: JobID) async throws {
184187
try await self.client.withTransaction(logger: logger) { connection in
185188
try await deleteFromQueue(jobID: jobID, connection: connection)
186189
if configuration.retentionPolicy.cancelled == .doNotRetain {
187-
try await delete(jobID: jobID)
190+
try await delete(jobID: jobID, connection: connection)
188191
} else {
189192
try await setStatus(jobID: jobID, status: .cancelled, connection: connection)
190193
}
@@ -199,6 +202,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
199202
/// - Parameters:
200203
/// - jobID: an existing job
201204
/// - Throws:
205+
@inlinable
202206
public func pause(jobID: UUID) async throws {
203207
try await self.client.withTransaction(logger: logger) { connection in
204208
try await deleteFromQueue(jobID: jobID, connection: connection)
@@ -214,6 +218,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
214218
/// - Parameters:
215219
/// - jobID: an existing job
216220
/// - Throws:
221+
@inlinable
217222
public func resume(jobID: JobID) async throws {
218223
try await self.client.withTransaction(logger: logger) { connection in
219224
try await setStatus(jobID: jobID, status: .pending, connection: connection)
@@ -235,7 +240,9 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
235240

236241
/// Push Job onto queue
237242
/// - Returns: Identifier of queued job
238-
@discardableResult public func push<Parameters>(_ jobRequest: JobRequest<Parameters>, options: JobOptions) async throws -> JobID {
243+
@discardableResult
244+
@inlinable
245+
public func push<Parameters>(_ jobRequest: JobRequest<Parameters>, options: JobOptions) async throws -> JobID {
239246
let jobID = JobID()
240247
try await self.client.withTransaction(logger: self.logger) { connection in
241248
try await self.add(jobID: jobID, jobRequest: jobRequest, queueName: configuration.queueName, connection: connection)
@@ -249,10 +256,10 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
249256
/// - jobID: Job instance ID
250257
/// - jobRequest: Job Request
251258
/// - options: Job retry options
259+
@inlinable
252260
public func retry<Parameters>(_ jobID: JobID, jobRequest: JobRequest<Parameters>, options: JobRetryOptions) async throws {
253-
let buffer = try self.jobRegistry.encode(jobRequest: jobRequest)
254261
try await self.client.withTransaction(logger: self.logger) { connection in
255-
try await self.updateJob(jobID: jobID, buffer: buffer, connection: connection)
262+
try await self.updateJob(jobID: jobID, jobRequest: jobRequest, connection: connection)
256263
try await self.addToQueue(
257264
jobID: jobID,
258265
queueName: configuration.queueName,
@@ -263,6 +270,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
263270
}
264271

265272
/// This is called to say job has finished processing and it can be deleted
273+
@inlinable
266274
public func finished(jobID: JobID) async throws {
267275
if configuration.retentionPolicy.completed == .doNotRetain {
268276
try await self.delete(jobID: jobID)
@@ -272,6 +280,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
272280
}
273281

274282
/// This is called to say job has failed to run and should be put aside
283+
@inlinable
275284
public func failed(jobID: JobID, error: Error) async throws {
276285
if configuration.retentionPolicy.failed == .doNotRetain {
277286
try await self.delete(jobID: jobID)
@@ -288,6 +297,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
288297
/// shutdown queue once all active jobs have been processed
289298
public func shutdownGracefully() async {}
290299

300+
@inlinable
291301
public func getMetadata(_ key: String) async throws -> ByteBuffer? {
292302
let stream = try await self.client.query(
293303
"SELECT value FROM swift_jobs.queues_metadata WHERE key = \(key) AND queue_name = \(configuration.queueName)",
@@ -299,6 +309,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
299309
return nil
300310
}
301311

312+
@inlinable
302313
public func setMetadata(key: String, value: ByteBuffer) async throws {
303314
try await self.client.query(
304315
"""
@@ -311,6 +322,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
311322
)
312323
}
313324

325+
@usableFromInline
314326
func popFirst() async throws -> JobQueueResult<JobID>? {
315327
enum PopFirstResult {
316328
case nothing
@@ -406,6 +418,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
406418
}
407419
}
408420

421+
@usableFromInline
409422
func add<Parameters>(jobID: JobID, jobRequest: JobRequest<Parameters>, queueName: String, connection: PostgresConnection) async throws {
410423
try await connection.query(
411424
"""
@@ -416,7 +429,9 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
416429
)
417430
}
418431

419-
func updateJob(jobID: JobID, buffer: ByteBuffer, connection: PostgresConnection) async throws {
432+
@usableFromInline
433+
func updateJob<Parameters>(jobID: JobID, jobRequest: JobRequest<Parameters>, connection: PostgresConnection) async throws {
434+
let buffer = try self.jobRegistry.encode(jobRequest: jobRequest)
420435
try await connection.query(
421436
"""
422437
UPDATE swift_jobs.jobs
@@ -429,6 +444,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
429444
)
430445
}
431446

447+
@usableFromInline
432448
func delete(jobID: JobID) async throws {
433449
try await self.client.query(
434450
"""
@@ -439,6 +455,18 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
439455
)
440456
}
441457

458+
@usableFromInline
459+
func delete(jobID: JobID, connection: PostgresConnection) async throws {
460+
try await connection.query(
461+
"""
462+
DELETE FROM swift_jobs.jobs
463+
WHERE id = \(jobID) AND queue_name = \(configuration.queueName)
464+
""",
465+
logger: self.logger
466+
)
467+
}
468+
469+
@usableFromInline
442470
func deleteFromQueue(jobID: JobID, connection: PostgresConnection) async throws {
443471
try await connection.query(
444472
"""
@@ -449,6 +477,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
449477
)
450478
}
451479

480+
@usableFromInline
452481
func addToQueue(jobID: JobID, queueName: String, options: JobOptions, connection: PostgresConnection) async throws {
453482
try await connection.query(
454483
"""
@@ -461,6 +490,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
461490
)
462491
}
463492

493+
@usableFromInline
464494
func setStatus(jobID: JobID, status: Status, connection: PostgresConnection) async throws {
465495
try await connection.query(
466496
"""
@@ -473,6 +503,7 @@ public final class PostgresJobQueue: JobQueueDriver, CancellableJobQueue, Resuma
473503
)
474504
}
475505

506+
@usableFromInline
476507
func setStatus(jobID: JobID, status: Status) async throws {
477508
try await self.client.query(
478509
"""
@@ -527,8 +558,10 @@ extension PostgresJobQueue {
527558
public struct AsyncIterator: AsyncIteratorProtocol {
528559
public typealias Element = JobQueueResult<JobID>
529560

561+
@usableFromInline
530562
let queue: PostgresJobQueue
531563

564+
@inlinable
532565
public func next() async throws -> Element? {
533566
while true {
534567
if self.queue.isStopped.withLockedValue({ $0 }) {

0 commit comments

Comments
 (0)