Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Nelaupe committed May 29, 2020
1 parent a1324db commit 498800b
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
2 changes: 0 additions & 2 deletions Sources/SwiftQueue/Constraint+Charging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ internal final class BatteryChargingConstraint: SimpleConstraint {
}

override func willSchedule(queue: SqOperationQueue, operation: SqOperation) throws {
guard operation.info.requireCharging else { return }

/// Start listening
NotificationCenter.default.addObserver(
self,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftQueue/Constraint+Deadline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Foundation
internal final class DeadlineConstraint: JobConstraint {

/// Cancel the job after a certain date
private let deadline: Date
internal let deadline: Date

required init(deadline: Date) {
self.deadline = deadline
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftQueue/Constraint+Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal final class NetworkConstraint: JobConstraint {

func willRun(operation: SqOperation) throws {
guard let reachability = reachability else { return }
guard hasCorrectNetwork(reachability: reachability, required: operation.info.requireNetwork) else {
guard hasCorrectNetwork(reachability: reachability) else {
try reachability.startNotifier()
return
}
Expand All @@ -66,7 +66,7 @@ internal final class NetworkConstraint: JobConstraint {
return true
}

if hasCorrectNetwork(reachability: reachability, required: operation.info.requireNetwork) {
if hasCorrectNetwork(reachability: reachability) {
return true
}

Expand All @@ -80,8 +80,8 @@ internal final class NetworkConstraint: JobConstraint {
return false
}

private func hasCorrectNetwork(reachability: Reachability, required: NetworkType) -> Bool {
switch required {
private func hasCorrectNetwork(reachability: Reachability) -> Bool {
switch networkType {
case .any:
return true
case .cellular:
Expand Down
4 changes: 3 additions & 1 deletion Sources/ios/SwiftQueueManager+BackgroundTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public extension SwiftQueueManager {
internal extension SqOperation {

func scheduleBackgroundTask() {
let request = BGProcessingTaskRequest(identifier: info.uuid)
guard let name = name else { return }

let request = BGProcessingTaskRequest(identifier: name)

request.requiresNetworkConnectivity = info.requireNetwork.rawValue > NetworkType.any.rawValue
request.requiresExternalPower = info.requireCharging
Expand Down
16 changes: 8 additions & 8 deletions SwiftQueue.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
FA56F5FA2137CE8A855A3E4C /* PBXBuildFile */ = {isa = PBXBuildFile; fileRef = FA56F5F64DB6D92CF36DCE56 /* Constraint+Persister.swift */; };
FA56F798BA513E48E5C686D4 /* BackgroundTasksTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F261936CF36C1851C98F /* BackgroundTasksTest.swift */; };
FA56F7C0E3D727C9A66CCF29 /* ConstraintTest+Delay.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F416033CDF0BBD61FDAA /* ConstraintTest+Delay.swift */; };
FA56F8AAA2E0C05A1AF58F03 /* ConstraintTests+Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F87D9FD87C51DF16D4CA /* ConstraintTests+Tag.swift */; };
FA56F8AAA2E0C05A1AF58F03 /* ConstraintTest+Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F87D9FD87C51DF16D4CA /* ConstraintTest+Tag.swift */; };
FA56F8BE268BE3AA86D1F130 /* Constraint+Retry.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F6CCE12F58650BB3E292 /* Constraint+Retry.swift */; };
FA56F8E7DE53E05A37EE566B /* PBXBuildFile */ = {isa = PBXBuildFile; fileRef = FA56FAFB4780356A52DD724F /* Constraint+Retry.swift */; };
FA56F914E099DE4C964201C6 /* PBXBuildFile */ = {isa = PBXBuildFile; fileRef = FA56F05E8805E399F134F752 /* Constraint+Repeat.swift */; };
Expand All @@ -123,7 +123,7 @@
FA56FDA63F614515591C584E /* Constraint+Retry.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F6CCE12F58650BB3E292 /* Constraint+Retry.swift */; };
FA56FE2B3E288481461351A1 /* Constraint+Repeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56FC0A482A04B6AAAFABE8 /* Constraint+Repeat.swift */; };
FA56FEFAC8E42473AAD457D0 /* Constraint+Retry.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F6CCE12F58650BB3E292 /* Constraint+Retry.swift */; };
FA56FF0EF53DA8E833154623 /* ConstraintTests+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F02306FFFB472A3393D3 /* ConstraintTests+Timeout.swift */; };
FA56FF0EF53DA8E833154623 /* ConstraintTest+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA56F02306FFFB472A3393D3 /* ConstraintTest+Timeout.swift */; };
FA56FFCCFE420E8833894FA8 /* PBXBuildFile */ = {isa = PBXBuildFile; fileRef = FA56F5F64DB6D92CF36DCE56 /* Constraint+Persister.swift */; };
OBJ_29 /* SwiftQueue.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = OBJ_13 /* SwiftQueue.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -170,7 +170,7 @@
D0B7C62E5894FA6EE00D3160 /* PersisterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersisterTests.swift; sourceTree = "<group>"; };
D0B7CB3B79E039D3B11D8921 /* JobBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JobBuilder.swift; path = SwiftQueue/JobBuilder.swift; sourceTree = "<group>"; };
D0B7CB571CECEEA34DD07398 /* SqOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SqOperationQueue.swift; path = SwiftQueue/SqOperationQueue.swift; sourceTree = "<group>"; };
FA56F02306FFFB472A3393D3 /* ConstraintTests+Timeout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTests+Timeout.swift"; sourceTree = "<group>"; };
FA56F02306FFFB472A3393D3 /* ConstraintTest+Timeout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTest+Timeout.swift"; sourceTree = "<group>"; };
FA56F036668D4A0239EFA83E /* Constraint+Tag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Tag.swift"; path = "SwiftQueue/Constraint+Tag.swift"; sourceTree = "<group>"; };
FA56F05E8805E399F134F752 /* Constraint+Repeat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Repeat.swift"; path = "SwiftQueue/Constraint+Repeat.swift"; sourceTree = "<group>"; };
FA56F261936CF36C1851C98F /* BackgroundTasksTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundTasksTest.swift; sourceTree = "<group>"; };
Expand All @@ -181,7 +181,7 @@
FA56F5F64DB6D92CF36DCE56 /* Constraint+Persister.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Persister.swift"; path = "SwiftQueue/Constraint+Persister.swift"; sourceTree = "<group>"; };
FA56F65D45103434092B39D0 /* ConstraintTest+Repeat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTest+Repeat.swift"; sourceTree = "<group>"; };
FA56F6CCE12F58650BB3E292 /* Constraint+Retry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Retry.swift"; path = "SwiftQueue/Constraint+Retry.swift"; sourceTree = "<group>"; };
FA56F87D9FD87C51DF16D4CA /* ConstraintTests+Tag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTests+Tag.swift"; sourceTree = "<group>"; };
FA56F87D9FD87C51DF16D4CA /* ConstraintTest+Tag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTest+Tag.swift"; sourceTree = "<group>"; };
FA56FAFB4780356A52DD724F /* Constraint+Retry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Retry.swift"; path = "SwiftQueue/Constraint+Retry.swift"; sourceTree = "<group>"; };
FA56FAFCBF719BE42562C7B9 /* ConstraintTest+Deadline.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConstraintTest+Deadline.swift"; sourceTree = "<group>"; };
FA56FC0A482A04B6AAAFABE8 /* Constraint+Repeat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Constraint+Repeat.swift"; path = "SwiftQueue/Constraint+Repeat.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -254,8 +254,8 @@
FA56F4FD493F5C1BAE7343A5 /* ConstraintTest+Network.swift */,
FA56FEB06791317BC26F7425 /* ConstraintTest+Retry.swift */,
FA56F65D45103434092B39D0 /* ConstraintTest+Repeat.swift */,
FA56F87D9FD87C51DF16D4CA /* ConstraintTests+Tag.swift */,
FA56F02306FFFB472A3393D3 /* ConstraintTests+Timeout.swift */,
FA56F87D9FD87C51DF16D4CA /* ConstraintTest+Tag.swift */,
FA56F02306FFFB472A3393D3 /* ConstraintTest+Timeout.swift */,
FA56F3AA5CDACA72626C2C35 /* ConstraintTest+Charging.swift */,
FA56F3B12631D552CA8553BF /* ConstraintTest+UniqueUUID.swift */,
);
Expand Down Expand Up @@ -584,8 +584,8 @@
FA56F487C74F65E78DFB3E90 /* ConstraintTest+Network.swift in Sources */,
FA56FC5FB80F2B1C4B0828AC /* ConstraintTest+Retry.swift in Sources */,
FA56F9FBDE678BAF1332B9F1 /* ConstraintTest+Repeat.swift in Sources */,
FA56F8AAA2E0C05A1AF58F03 /* ConstraintTests+Tag.swift in Sources */,
FA56FF0EF53DA8E833154623 /* ConstraintTests+Timeout.swift in Sources */,
FA56F8AAA2E0C05A1AF58F03 /* ConstraintTest+Tag.swift in Sources */,
FA56FF0EF53DA8E833154623 /* ConstraintTest+Timeout.swift in Sources */,
FA56F5D6F3971A231B065F92 /* ConstraintTest+Charging.swift in Sources */,
FA56FD6078FD2EAF4AF82519 /* ConstraintTest+UniqueUUID.swift in Sources */,
);
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftQueueTests/ConstraintTest+Delay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,30 @@ class ConstraintTestDelay: XCTestCase {
job.assertSingleCompletion()
}

func testDelayWhenDeserialize() {
let (type, job) = (UUID().uuidString, TestJob())

let creator = TestCreator([type: job])

let group = UUID().uuidString

let json = JobBuilder(type: type)
.parallel(queueName: group)
.delay(time: 10)
.build(job: job)
.toJSONStringSafe()

let persister = PersisterTracker(key: UUID().uuidString)
persister.put(queueName: group, taskId: UUID().uuidString, data: json)

let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: persister).build()

manager.cancelAllOperations()
job.assertRemovedBeforeRun(reason: .canceled)

XCTAssertEqual(group, persister.restoreQueueName)

manager.waitUntilAllOperationsAreFinished()
}

}
1 change: 0 additions & 1 deletion Tests/SwiftQueueTests/SwiftQueueManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class SwiftQueueManagerTests: XCTestCase {
JobBuilder(type: type)
.priority(priority: .veryHigh)
.service(quality: .background)

.schedule(manager: manager)

job.awaitForRemoval()
Expand Down

0 comments on commit 498800b

Please sign in to comment.