Skip to content

Commit

Permalink
provider updates (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 authored Jun 21, 2019
1 parent 1b75e16 commit b99a22e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
10 changes: 5 additions & 5 deletions Sources/Jobs/JobsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class JobsCommand: Command {
public let jobContext: JobContext

/// The registered `JobsConfiguration`
public let config: JobsConfiguration
public let configuration: JobsConfiguration

private var isShuttingDown: Bool {
get {
Expand All @@ -48,13 +48,13 @@ public final class JobsCommand: Command {
/// - Parameters:
/// - queueService: The registered `QueueService`
/// - jobContext: The registered `JobContext` object
/// - config: The registered `JobsConfiguration` object
public init(queueService: QueueService, jobContext: JobContext, config: JobsConfiguration) {
/// - configuration: The registered `JobsConfiguration` object
public init(queueService: QueueService, jobContext: JobContext, configuration: JobsConfiguration) {
_lock = NSLock()

self.queueService = queueService
self.jobContext = jobContext
self.config = config
self.configuration = configuration
}

/// See `Command`.`run(using:)`
Expand Down Expand Up @@ -138,7 +138,7 @@ public final class JobsCommand: Command {
}
}

guard let job = self.config.make(for: jobStorage.jobName) else {
guard let job = self.configuration.make(for: jobStorage.jobName) else {
return eventLoop.makeFailedFuture(Abort(.internalServerError, reason: "Please register \(jobStorage.jobName)"))
}

Expand Down
35 changes: 26 additions & 9 deletions Sources/Jobs/JobsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@ import NIO

/// A provider used to setup the `Jobs` package
public struct JobsProvider: Provider {

/// See `Provider`.`register(_ services:)`
public func register(_ s: inout Services) {
s.register(
QueueService.self
) { container -> QueueService in
let persistenceLayer = try container.make(JobsPersistenceLayer.self)

return QueueService(refreshInterval: self.refreshInterval,
persistenceLayer: persistenceLayer,
persistenceKey: self.persistenceKey)
s.register(QueueService.self) { container in
return try QueueService(
refreshInterval: self.refreshInterval,
persistenceLayer: container.make(JobsPersistenceLayer.self),
persistenceKey: self.persistenceKey
)
}

s.register(JobsConfiguration.self) { container in
return JobsConfiguration()
}

s.register(JobsCommand.self) { c in
return try .init(
queueService: c.make(),
jobContext: c.make(),
configuration: c.make()
)
}

s.register(JobContext.self) { c in
return .init(eventLoop: c.eventLoop)
}

s.extend(CommandConfiguration.self) { configuration, c in
try configuration.use(c.make(JobsCommand.self), as: "jobs")
}
}

Expand Down

0 comments on commit b99a22e

Please sign in to comment.