Skip to content

Commit

Permalink
Rename queue to queue name
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Nelaupe committed May 6, 2019
1 parent e4a4104 commit 6b7970a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
12 changes: 10 additions & 2 deletions Sources/SwiftQueue/JobBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public final class JobBuilder {
}

/// Job in different groups can run in parallel
@available(*, deprecated, renamed: "parallel")
public func group(name: String) -> Self {
assertNotEmptyString(name)
info.group = name
info.queueName = name
return self
}

/// Job in different groups can run in parallel
public func parallel(queueName: String) -> Self {
assertNotEmptyString(queueName)
info.queueName = queueName
return self
}

Expand Down Expand Up @@ -123,7 +131,7 @@ public final class JobBuilder {
assert(JSONSerialization.isValidJSONObject(info.params))
}

let queue = manager.getQueue(queueName: info.group)
let queue = manager.getQueue(queueName: info.queueName)
let job = queue.createHandler(type: info.type, params: info.params)

queue.addOperation(build(job: job, logger: manager.logger))
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftQueue/JobInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public struct JobInfo {
/// Type of job to create actual `Job` instance
let type: String

/// Queue name
var queueName: String

/// Unique identifier for a job
var uuid: String

/// Override job when scheduling a job with same uuid
var override: Bool

/// Queue name
var group: String

/// Set of identifiers
var tags: Set<String>

Expand Down Expand Up @@ -72,9 +72,9 @@ public struct JobInfo {
var currentRepetition: Int

init(type: String,
queueName: String = "GLOBAL",
uuid: String = UUID().uuidString,
override: Bool = false,
group: String = "GLOBAL",
tags: Set<String> = Set<String>(),
delay: TimeInterval? = nil,
deadline: Date? = nil,
Expand All @@ -89,9 +89,9 @@ public struct JobInfo {
requireCharging: Bool = false) {

self.type = type
self.queueName = queueName
self.uuid = uuid
self.override = override
self.group = group
self.tags = tags
self.delay = delay
self.deadline = deadline
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftQueue/JobInfoSerializer+Decodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension JobInfo: Decodable {
case type = "type"
case uuid = "uuid"
case override = "override"
case group = "group"
case queueName = "group"
case tags = "tags"
case delay = "delay"
case deadline = "deadline"
Expand All @@ -79,7 +79,7 @@ extension JobInfo: Decodable {
let type: String = try container.decode(String.self, forKey: .type)
let uuid: String = try container.decode(String.self, forKey: .uuid)
let override: Bool = try container.decode(Bool.self, forKey: .override)
let group: String = try container.decode(String.self, forKey: .group)
let queueName: String = try container.decode(String.self, forKey: .queueName)
let tags: Set<String> = try container.decode(Set.self, forKey: .tags)
let delay: TimeInterval? = try container.decodeIfPresent(TimeInterval.self, forKey: .delay)
let deadline: Date? = try container.decodeIfPresent(Date.self, forKey: .deadline)
Expand All @@ -95,9 +95,9 @@ extension JobInfo: Decodable {

self.init(
type: type,
queueName: queueName,
uuid: uuid,
override: override,
group: group,
tags: tags,
delay: delay,
deadline: deadline,
Expand All @@ -120,7 +120,7 @@ extension JobInfo: Encodable {
try container.encode(type, forKey: .type)
try container.encode(uuid, forKey: .uuid)
try container.encode(override, forKey: .override)
try container.encode(group, forKey: .group)
try container.encode(queueName, forKey: .queueName)
try container.encode(tags, forKey: .tags)
try container.encode(delay, forKey: .delay)
try container.encode(deadline, forKey: .deadline)
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftQueue/JobInfoSerializer+V1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal extension JobInfo {
dict[JobInfoKeys.type.stringValue] = self.type
dict[JobInfoKeys.uuid.stringValue] = self.uuid
dict[JobInfoKeys.override.stringValue] = self.override
dict[JobInfoKeys.group.stringValue] = self.group
dict[JobInfoKeys.queueName.stringValue] = self.queueName
dict[JobInfoKeys.tags.stringValue] = Array(self.tags)
dict[JobInfoKeys.delay.stringValue] = self.delay
dict[JobInfoKeys.deadline.stringValue] = self.deadline.map(dateFormatter.string)
Expand All @@ -95,7 +95,7 @@ internal extension JobInfo {
mutating func bind(dictionary: [String: Any]) throws {
dictionary.assign(JobInfoKeys.uuid.stringValue, &self.uuid)
dictionary.assign(JobInfoKeys.override.stringValue, &self.override)
dictionary.assign(JobInfoKeys.group.stringValue, &self.group)
dictionary.assign(JobInfoKeys.queueName.stringValue, &self.queueName)
dictionary.assign(JobInfoKeys.tags.stringValue, &self.tags) { (array: [String]) -> Set<String> in Set(array) }
dictionary.assign(JobInfoKeys.delay.stringValue, &self.delay)
dictionary.assign(JobInfoKeys.deadline.stringValue, &self.deadline, dateFormatter.date)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftQueueTests/SwiftQueueBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SwiftQueueBuilderTests: XCTestCase {
let groupName = UUID().uuidString

let jobInfo = try toJobInfo(serializer, type: type, JobBuilder(type: type).group(name: groupName))
XCTAssertEqual(jobInfo?.group, groupName)
XCTAssertEqual(jobInfo?.queueName, groupName)
}
}

Expand Down

0 comments on commit 6b7970a

Please sign in to comment.