-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Nelaupe
committed
Jun 8, 2020
1 parent
e547d26
commit 2a9e3c6
Showing
18 changed files
with
425 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by Lucas Nelaupe on 25/5/20. | ||
// | ||
|
||
import Foundation | ||
|
||
internal class PersisterConstraint: SimpleConstraint { | ||
|
||
private let serializer: JobInfoSerializer | ||
|
||
private let persister: JobPersister | ||
|
||
init(serializer: JobInfoSerializer, persister: JobPersister) { | ||
self.serializer = serializer | ||
self.persister = persister | ||
} | ||
|
||
override func willSchedule(queue: SqOperationQueue, operation: SqOperation) throws { | ||
let data = try serializer.serialize(info: operation.info) | ||
let name = operation.name ?? "" | ||
let queueName = queue.name ?? "" | ||
assertNotEmptyString(name) | ||
assertNotEmptyString(queueName) | ||
persister.put(queueName: queueName, taskId: name, data: data) | ||
} | ||
|
||
func remove(queueName: String, taskId: String) { | ||
persister.remove(queueName: queueName, taskId: taskId) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Created by Lucas Nelaupe on 26/5/20. | ||
// | ||
|
||
import Foundation | ||
|
||
internal final class TagConstraint: SimpleConstraint, CodableConstraint { | ||
|
||
internal var tags: Set<String> | ||
|
||
required init(tags: Set<String>) { | ||
self.tags = tags | ||
} | ||
|
||
convenience init?(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: TagConstraintKey.self) | ||
if container.contains(.tags) { | ||
try self.init(tags: container.decode(Set<String>.self, forKey: .tags)) | ||
} else { return nil } | ||
} | ||
|
||
func insert(tag: String) { | ||
tags.insert(tag) | ||
} | ||
|
||
func contains(tag: String) -> Bool { | ||
return tags.contains(tag) | ||
} | ||
|
||
private enum TagConstraintKey: String, CodingKey { | ||
case tags | ||
} | ||
|
||
func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: TagConstraintKey.self) | ||
try container.encode(tags, forKey: .tags) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.