Skip to content

chore: rework mutagen controller, add polling #65

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

Merged
merged 5 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
// Initialize file sync.
var syncSessionCts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var syncSessionController = _services.GetRequiredService<ISyncSessionController>();
_ = syncSessionController.Initialize(syncSessionCts.Token).ContinueWith(t =>
_ = syncSessionController.RefreshState(syncSessionCts.Token).ContinueWith(t =>
{
// TODO: log
#if DEBUG
Expand Down
9 changes: 4 additions & 5 deletions App/Models/RpcModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Coder.Desktop.Vpn.Proto;

namespace Coder.Desktop.App.Models;
Expand All @@ -26,18 +25,18 @@ public class RpcModel

public VpnLifecycle VpnLifecycle { get; set; } = VpnLifecycle.Unknown;

public List<Workspace> Workspaces { get; set; } = [];
public IReadOnlyList<Workspace> Workspaces { get; set; } = [];

public List<Agent> Agents { get; set; } = [];
public IReadOnlyList<Agent> Agents { get; set; } = [];

public RpcModel Clone()
{
return new RpcModel
{
RpcLifecycle = RpcLifecycle,
VpnLifecycle = VpnLifecycle,
Workspaces = Workspaces.ToList(),
Agents = Agents.ToList(),
Workspaces = Workspaces,
Agents = Agents,
};
}
}
43 changes: 43 additions & 0 deletions App/Models/SyncSessionControllerStateModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Collections.Generic;

namespace Coder.Desktop.App.Models;

public enum SyncSessionControllerLifecycle
{
// Uninitialized means that the daemon has not been started yet. This can
// be resolved by calling RefreshState (or any other RPC method
// successfully).
Uninitialized,

// Stopped means that the daemon is not running. This could be because:
// - It was never started (pre-Initialize)
// - It was stopped due to no sync sessions (post-Initialize, post-operation)
// - The last start attempt failed (DaemonError will be set)
// - The last daemon process crashed (DaemonError will be set)
Stopped,

// Running is the normal state where the daemon is running and managing
// sync sessions. This is only set after a successful start (including
// being able to connect to the daemon).
Running,
}

public class SyncSessionControllerStateModel
{
public SyncSessionControllerLifecycle Lifecycle { get; init; } = SyncSessionControllerLifecycle.Stopped;

/// <summary>
/// May be set when Lifecycle is Stopped to signify that the daemon failed
/// to start or unexpectedly crashed.
/// </summary>
public string? DaemonError { get; init; }

public required string DaemonLogFilePath { get; init; }

/// <summary>
/// This contains the last known state of all sync sessions. Sync sessions
/// are periodically refreshed if the daemon is running. This list is
/// sorted by creation time.
/// </summary>
public IReadOnlyList<SyncSessionModel> SyncSessions { get; init; } = [];
}
4 changes: 3 additions & 1 deletion App/Models/SyncSessionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public class SyncSessionModel
{
public readonly string Identifier;
public readonly string Name;
public readonly DateTime CreatedAt;

public readonly string AlphaName;
public readonly string AlphaPath;
Expand All @@ -232,7 +233,7 @@ public string StatusDetails
get
{
var str = $"{StatusString} ({StatusCategory})\n\n{StatusDescription}";
foreach (var err in Errors) str += $"\n\nError: {err}";
foreach (var err in Errors) str += $"\n\n{err}";
foreach (var conflict in Conflicts) str += $"\n\n{conflict.Description()}";
if (OmittedConflicts > 0) str += $"\n\n{OmittedConflicts:N0} conflicts omitted";
return str;
Expand All @@ -253,6 +254,7 @@ public SyncSessionModel(State state)
{
Identifier = state.Session.Identifier;
Name = state.Session.Name;
CreatedAt = state.Session.CreationTime.ToDateTime();

(AlphaName, AlphaPath) = NameAndPathFromUrl(state.Session.Alpha);
(BetaName, BetaPath) = NameAndPathFromUrl(state.Session.Beta);
Expand Down
Loading