Changing timeout to timespan

Updating publish task to have parameters for the timeout and wait for live parameters.
This commit is contained in:
Kevin Bost
2024-12-26 23:27:52 -08:00
committed by Caelan
parent 21c1afc9a2
commit 63b04c82dd
6 changed files with 16 additions and 9 deletions

View File

@@ -29,7 +29,7 @@ public class MSBuildLogger(TaskLoggingHelper loggingHelper) : ILogger, IFancyCon
try { try {
await fn(x => { }).ConfigureAwait(false); await fn(x => { }).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.LogError(ex, "Error running task {0}", name); this.LogError(ex, "Error running task {taskName}", name);
throw; throw;
} }
} }
@@ -39,7 +39,7 @@ public class MSBuildLogger(TaskLoggingHelper loggingHelper) : ILogger, IFancyCon
try { try {
return await fn(x => { }).ConfigureAwait(false); return await fn(x => { }).ConfigureAwait(false);
} catch (Exception ex) { } catch (Exception ex) {
this.LogError(ex, "Error running task {0}", name); this.LogError(ex, "Error running task {taskName}", name);
throw; throw;
} }
} }

View File

@@ -1,4 +1,5 @@
using System.Threading; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -17,17 +18,19 @@ public class PublishTask : MSBuildAsyncTask
public string? ApiKey { get; set; } public string? ApiKey { get; set; }
public double Timeout { get; set; } = 30d; public string? Timeout { get; set; }
public bool WaitForLive { get; set; } public bool WaitForLive { get; set; }
protected override async Task<bool> ExecuteAsync(CancellationToken cancellationToken) protected override async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
{ {
TimeSpan timeout = Timeout == null ? TimeSpan.FromMinutes(30) : TimeSpan.Parse(Timeout);
//System.Diagnostics.Debugger.Launch(); //System.Diagnostics.Debugger.Launch();
var options = new VelopackFlowServiceOptions { var options = new VelopackFlowServiceOptions {
VelopackBaseUrl = ServiceUrl, VelopackBaseUrl = ServiceUrl,
ApiKey = ApiKey, ApiKey = ApiKey,
Timeout = Timeout, Timeout = timeout,
}; };
var loginOptions = new VelopackFlowLoginOptions() { var loginOptions = new VelopackFlowLoginOptions() {
@@ -37,8 +40,7 @@ public class PublishTask : MSBuildAsyncTask
}; };
var client = new VelopackFlowServiceClient(options, Logger, Logger); var client = new VelopackFlowServiceClient(options, Logger, Logger);
CancellationToken token = CancellationToken.None; if (!await client.LoginAsync(loginOptions, false, cancellationToken).ConfigureAwait(false)) {
if (!await client.LoginAsync(loginOptions, false, token)) {
Logger.LogWarning("Not logged into Velopack Flow service, skipping publish. Please run vpk login."); Logger.LogWarning("Not logged into Velopack Flow service, skipping publish. Please run vpk login.");
return true; return true;
} }

View File

@@ -23,6 +23,8 @@
<VelopackPackAuthors Condition="'$(VelopackPackAuthors)' == ''">$(Authors)</VelopackPackAuthors> <VelopackPackAuthors Condition="'$(VelopackPackAuthors)' == ''">$(Authors)</VelopackPackAuthors>
<VelopackTargetRuntime Condition="'$(VelopackTargetRuntime)' == ''">$(RuntimeIdentifier)</VelopackTargetRuntime> <VelopackTargetRuntime Condition="'$(VelopackTargetRuntime)' == ''">$(RuntimeIdentifier)</VelopackTargetRuntime>
<VelopackShortcuts Condition="'$(VelopackShortcuts)' == ''">Desktop,StartMenuRoot</VelopackShortcuts> <VelopackShortcuts Condition="'$(VelopackShortcuts)' == ''">Desktop,StartMenuRoot</VelopackShortcuts>
<VelopackHttpTimeout Condition="'$(VelopackHttpTimeout)' == ''">00:30:00</VelopackHttpTimeout>
<VelopackWaitForLive Condition="'$(VelopackWaitForLive)' == ''">false</VelopackWaitForLive>
<!-- Allows a cross platform app (eg. Avalonia) to specify all three via csproj and have them applied correctly --> <!-- Allows a cross platform app (eg. Avalonia) to specify all three via csproj and have them applied correctly -->
<!-- TODO: this should probably switch based on the target RID and not the current OS, but we currently don't <!-- TODO: this should probably switch based on the target RID and not the current OS, but we currently don't
@@ -100,6 +102,8 @@
ServiceUrl="$(VelopackFlowServiceUrl)" ServiceUrl="$(VelopackFlowServiceUrl)"
ApiKey="$(VelopackFlowApiKey)" ApiKey="$(VelopackFlowApiKey)"
Channel="$(VelopackChannel)" Channel="$(VelopackChannel)"
Timeout="$(VelopackHttpTimeout)"
WaitForLive="$(VelopackWaitForLive)"
/> />
</Target> </Target>
</Project> </Project>

View File

@@ -52,7 +52,7 @@ public class VelopackFlowServiceClient(
var client = new HttpClient(handler); var client = new HttpClient(handler);
client.DefaultRequestHeaders.Authorization = Authorization; client.DefaultRequestHeaders.Authorization = Authorization;
client.Timeout = TimeSpan.FromMinutes(Options.Timeout); client.Timeout = Options.Timeout;
return client; return client;
} }

View File

@@ -6,5 +6,5 @@ public class VelopackFlowServiceOptions
public string? ApiKey { get; set; } = string.Empty; public string? ApiKey { get; set; } = string.Empty;
public double Timeout { get; set; } = 30d; public TimeSpan Timeout { get; set; } = TimeSpan.FromMinutes(30);
} }

View File

@@ -53,6 +53,7 @@ public static partial class OptionMapper
public static partial DeltaPatchOptions ToOptions(this DeltaPatchCommand cmd); public static partial DeltaPatchOptions ToOptions(this DeltaPatchCommand cmd);
[MapperIgnoreTarget(nameof(LocalDownloadOptions.Timeout))]
public static partial LoginOptions ToOptions(this LoginCommand cmd); public static partial LoginOptions ToOptions(this LoginCommand cmd);
public static partial LogoutOptions ToOptions(this LogoutCommand cmd); public static partial LogoutOptions ToOptions(this LogoutCommand cmd);