-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: create & delete sync sessions over gRPC #119
Merged
+155
−50
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb25fe5
chore: create & delete sync sessions over gRPC
ethanndickson 1278070
pausing & unpausing
ethanndickson dfd1bc8
fixup
ethanndickson 1b64444
set generous timeouts on session requests
ethanndickson 91a5b36
very important fix
ethanndickson 58f9775
bump timeouts
ethanndickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import NIOCore | ||
|
||
public extension MutagenDaemon { | ||
func refreshSessions() async { | ||
guard case .running = state else { return } | ||
let sessions: Synchronization_ListResponse | ||
do { | ||
sessions = try await client!.sync.list(Synchronization_ListRequest.with { req in | ||
req.selection = .with { selection in | ||
selection.all = true | ||
} | ||
}) | ||
} catch { | ||
state = .failed(.grpcFailure(error)) | ||
return | ||
} | ||
sessionState = sessions.sessionStates.map { FileSyncSession(state: $0) } | ||
} | ||
|
||
func createSession( | ||
localPath: String, | ||
agentHost: String, | ||
remotePath: String | ||
) async throws(DaemonError) { | ||
if case .stopped = state { | ||
do throws(DaemonError) { | ||
try await start() | ||
} catch { | ||
state = .failed(error) | ||
throw error | ||
} | ||
} | ||
let (stream, promptID) = try await host() | ||
defer { stream.cancel() } | ||
let req = Synchronization_CreateRequest.with { req in | ||
req.prompter = promptID | ||
req.specification = .with { spec in | ||
spec.alpha = .with { alpha in | ||
alpha.protocol = .local | ||
alpha.path = localPath | ||
} | ||
spec.beta = .with { beta in | ||
beta.protocol = .ssh | ||
beta.host = agentHost | ||
beta.path = remotePath | ||
} | ||
// TODO: Ingest a config from somewhere | ||
spec.configuration = Synchronization_Configuration() | ||
spec.configurationAlpha = Synchronization_Configuration() | ||
spec.configurationBeta = Synchronization_Configuration() | ||
} | ||
} | ||
do { | ||
// The first creation will need to transfer the agent binary | ||
// TODO: Because this is pretty long, we should show progress updates | ||
// using the prompter messages | ||
_ = try await client!.sync.create(req, callOptions: .init(timeLimit: .timeout(sessionMgmtReqTimeout * 4))) | ||
} catch { | ||
throw .grpcFailure(error) | ||
} | ||
await refreshSessions() | ||
} | ||
|
||
func deleteSessions(ids: [String]) async throws(DaemonError) { | ||
// Terminating sessions does not require prompting, according to the | ||
// Mutagen CLI | ||
let (stream, promptID) = try await host(allowPrompts: false) | ||
defer { stream.cancel() } | ||
guard case .running = state else { return } | ||
do { | ||
_ = try await client!.sync.terminate(Synchronization_TerminateRequest.with { req in | ||
req.prompter = promptID | ||
req.selection = .with { selection in | ||
selection.specifications = ids | ||
} | ||
}, callOptions: .init(timeLimit: .timeout(sessionMgmtReqTimeout))) | ||
} catch { | ||
throw .grpcFailure(error) | ||
} | ||
await refreshSessions() | ||
} | ||
|
||
func pauseSessions(ids: [String]) async throws(DaemonError) { | ||
// Pausing sessions does not require prompting, according to the | ||
// Mutagen CLI | ||
let (stream, promptID) = try await host(allowPrompts: false) | ||
defer { stream.cancel() } | ||
guard case .running = state else { return } | ||
do { | ||
_ = try await client!.sync.pause(Synchronization_PauseRequest.with { req in | ||
req.prompter = promptID | ||
req.selection = .with { selection in | ||
selection.specifications = ids | ||
} | ||
}, callOptions: .init(timeLimit: .timeout(sessionMgmtReqTimeout))) | ||
} catch { | ||
throw .grpcFailure(error) | ||
} | ||
await refreshSessions() | ||
} | ||
|
||
func resumeSessions(ids: [String]) async throws(DaemonError) { | ||
// Resuming sessions does not require prompting, according to the | ||
// Mutagen CLI | ||
let (stream, promptID) = try await host(allowPrompts: false) | ||
defer { stream.cancel() } | ||
guard case .running = state else { return } | ||
do { | ||
_ = try await client!.sync.resume(Synchronization_ResumeRequest.with { req in | ||
req.prompter = promptID | ||
req.selection = .with { selection in | ||
selection.specifications = ids | ||
} | ||
}, callOptions: .init(timeLimit: .timeout(sessionMgmtReqTimeout))) | ||
} catch { | ||
throw .grpcFailure(error) | ||
} | ||
await refreshSessions() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always have two outgoing gRPC requests at once, the prompter, and the actual request we're trying to make. This creates a second OS thread for gRPC to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh 2 os threads might be overkill