forked from avito-tech/Emcee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract WorkerRegisterer from SynchronousQueueClient
- Loading branch information
1 parent
f43bda0
commit e0d4b04
Showing
28 changed files
with
302 additions
and
119 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
Sources/QueueClient/Clients/WorkerRegisterer/WorkerRegisterer.swift
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,9 @@ | ||
import Models | ||
import RequestSender | ||
|
||
public protocol WorkerRegisterer { | ||
func registerWithServer( | ||
workerId: WorkerId, | ||
completion: @escaping (Either<WorkerConfiguration, RequestSenderError>) -> Void | ||
) throws | ||
} |
32 changes: 32 additions & 0 deletions
32
Sources/QueueClient/Clients/WorkerRegisterer/WorkerRegistererImpl.swift
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,32 @@ | ||
import RequestSender | ||
import Models | ||
import RESTMethods | ||
|
||
public final class WorkerRegistererImpl: WorkerRegisterer { | ||
private let requestSender: RequestSender | ||
|
||
public init(requestSender: RequestSender) { | ||
self.requestSender = requestSender | ||
} | ||
|
||
public func registerWithServer( | ||
workerId: WorkerId, | ||
completion: @escaping (Either<WorkerConfiguration, RequestSenderError>) -> Void | ||
) throws { | ||
try requestSender.sendRequestWithCallback( | ||
pathWithSlash: RESTMethod.registerWorker.withPrependingSlash, | ||
payload: RegisterWorkerRequest(workerId: workerId), | ||
callback: { (result: Either<RegisterWorkerResponse, RequestSenderError>) in | ||
switch result { | ||
case .left(let response): | ||
switch response { | ||
case .workerRegisterSuccess(let workerConfiguration): | ||
completion(Either.success(workerConfiguration)) | ||
} | ||
case .right(let requestSenderError): | ||
completion(Either.error(requestSenderError)) | ||
} | ||
} | ||
) | ||
} | ||
} |
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
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.