Skip to content

Commit 120fde4

Browse files
committed
Experiment with polling
- Starting on #19 in a timer-based implementation
1 parent 8ab99f1 commit 120fde4

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/Options/ExtensionOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,16 @@ public class ExtensionOptions : BaseOptionModel<ExtensionOptions>
1717
[Description("The maximum number of runs to retrieve")]
1818
[DefaultValue(10)]
1919
public int MaxRuns { get; set; } = 10;
20+
21+
[Category("Query Settings")]
22+
[DisplayName("Refresh Active Jobs")]
23+
[Description("Whether to poll/refresh when pending/active jobs are going")]
24+
[DefaultValue(false)]
25+
public bool RefreshActiveJobs { get; set; } = false;
26+
27+
[Category("Query Settings")]
28+
[DisplayName("Refresh Interval (in seconds)")]
29+
[Description("The interval (in seconds) to poll/refresh when pending/active jobs are going")]
30+
[DefaultValue(5)]
31+
public int RefreshInterval { get; set; } = 5;
2032
}

src/ToolWindows/GHActionsToolWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<RowDefinition Height="Auto" />
5858
<RowDefinition Height="*" />
5959
</Grid.RowDefinitions>
60-
<ProgressBar x:Name="refreshProgress" Height="5" Grid.Row="0" Visibility="Collapsed" />
60+
<ProgressBar x:Name="refreshProgress" Height="5" Grid.Row="0" Visibility="Hidden"/>
6161
<Grid Grid.Row="1">
6262
<TextBlock HorizontalAlignment="Center" x:Name="MessageArea" />
6363
<ScrollViewer VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="5,5,0,0" x:Name="ActionsInfoPanel">

src/ToolWindows/GHActionsToolWindow.xaml.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public partial class GHActionsToolWindow : UserControl
2222
{
2323
private readonly RepoInfo _repoInfo = null;
2424
private readonly ToolWindowMessenger _toolWindowMessenger = null;
25+
private int maxRuns = 10;
26+
private bool refreshPending = false;
27+
private int refreshInterval = 5;
28+
2529

2630
public GHActionsToolWindow(ToolWindowMessenger toolWindowMessenger)
2731
{
@@ -68,6 +72,12 @@ public async Task GetRepoInfoAsync()
6872
_repoInfo.IsGitHub = false;
6973
_repoInfo.RepoUrl = null;
7074

75+
// get settings
76+
var generalSettings = await ExtensionOptions.GetLiveInstanceAsync();
77+
maxRuns = generalSettings.MaxRuns;
78+
refreshInterval = generalSettings.RefreshInterval;
79+
refreshPending = generalSettings.RefreshActiveJobs;
80+
7181
// find the git folder
7282
var solution = await VS.Solutions.GetCurrentSolutionAsync();
7383
if (solution is null)
@@ -127,10 +137,6 @@ private async Task LoadDataAsync()
127137
MessageArea.Visibility = Visibility.Collapsed;
128138
ActionsInfoPanel.Visibility = Visibility.Visible;
129139

130-
// get the settings
131-
var generalSettings = await ExtensionOptions.GetLiveInstanceAsync();
132-
var maxRuns = generalSettings.MaxRuns;
133-
134140
refreshProgress.IsIndeterminate = true;
135141
refreshProgress.Visibility = Visibility.Visible;
136142

@@ -164,6 +170,22 @@ private async Task LoadDataAsync()
164170
RunNumber = run.RunNumber.ToString()
165171
};
166172

173+
if (refreshPending)
174+
{
175+
var timer = new System.Timers.Timer(refreshInterval*1000);
176+
timer.Elapsed += async (sender, e) =>
177+
{
178+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
179+
await LoadDataAsync();
180+
};
181+
timer.AutoReset = false;
182+
183+
if (((run.Status == WorkflowRunStatus.Queued) || (run.Status == WorkflowRunStatus.InProgress) || (run.Status == WorkflowRunStatus.Pending) || (run.Status == WorkflowRunStatus.Waiting)))
184+
{
185+
timer.Start();
186+
}
187+
}
188+
167189
// get the jobs for the run
168190
var jobs = await client.Actions.Workflows.Jobs?.List(_repoInfo.RepoOwner, _repoInfo.RepoName, run.Id);
169191

@@ -218,7 +240,7 @@ private async Task LoadDataAsync()
218240
}
219241

220242
CurrentBranchExpander.IsExpanded = true;
221-
refreshProgress.Visibility = Visibility.Collapsed;
243+
refreshProgress.Visibility = Visibility.Hidden;
222244
refreshProgress.IsIndeterminate = false;
223245
}
224246

0 commit comments

Comments
 (0)