Skip to content

Commit

Permalink
Add Method to query all jobs (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas34 authored Nov 3, 2019
1 parent 8bb3ae9 commit 7302259
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Sources/SwiftQueue/SwiftQueueManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,36 @@ public final class SwiftQueueManager {
}
}

}

/// Extension to query Job Manager
public extension SwiftQueueManager {
/// number of queue
public func queueCount() -> Int {
func queueCount() -> Int {
return manage.values.count
}

/// number of jobs for all queues
public func jobCount() -> Int {
func jobCount() -> Int {
var count = 0
for element in manage.values {
count += element.operationCount
}
return count
}

/// Return queues UUID with the list of Jobs inside
func getAll() -> [String: [JobInfo]] {
var result = [String: [JobInfo]]()
for (queueUuid, queue) in manage {
var infos = [JobInfo]()
for case let operation as SqOperation in queue.operations {
infos.append(operation.info)
}
result[queueUuid] = infos
}
return result
}
}

internal extension SwiftQueueManager {
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftQueueTests/SwiftQueueManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,11 @@ class SwiftQueueManagerTests: XCTestCase {
job.assertNoRun()
}

public func testGetAll() {
let creator = TestCreator([:])
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()

XCTAssertEqual(0, manager.getAll().count)
}

}

0 comments on commit 7302259

Please sign in to comment.