Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Jul 7, 2023
1 parent 85bf79f commit 5dde26c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/netcore/Wexflow.Clients.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Wexflow.Core.Service.Client;
using Wexflow.Core.Service.Contracts;

Expand Down Expand Up @@ -41,7 +41,7 @@ private class Options
public bool Wait { get; set; }
}

private static void Main(string[] args)
private static async Task Main(string[] args)
{
try
{
Expand All @@ -51,7 +51,7 @@ private static void Main(string[] args)

Parser parser = new(cfg => cfg.CaseInsensitiveEnumValues = true);

async void Action(Options o)
async Task<int> ExecuteCommand(Options o)
{
WexflowServiceClient client = new(config["WexflowWebServiceUri"]);
var username = config["Username"];
Expand All @@ -61,7 +61,7 @@ async void Action(Options o)
if (workflows.All(w => w.Id != o.WorkflowId))
{
Console.WriteLine("Workflow id {0} is incorrect.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

WorkflowInfo workflow;
Expand All @@ -73,12 +73,12 @@ async void Action(Options o)

if (o.Wait)
{
Thread.Sleep(1000);
await Task.Delay(1000);
workflow = await client.GetWorkflow(username, password, o.WorkflowId);
var isRunning = workflow.IsRunning;
while (isRunning)
{
Thread.Sleep(100);
await Task.Delay(100);
workflow = await client.GetWorkflow(username, password, o.WorkflowId);
isRunning = workflow.IsRunning;
}
Expand All @@ -91,7 +91,7 @@ async void Action(Options o)
if (!workflow.IsRunning)
{
Console.WriteLine("Workflow {0} is not running to be suspended.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

await client.SuspendWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
Expand All @@ -102,7 +102,7 @@ async void Action(Options o)
if (!workflow.IsRunning)
{
Console.WriteLine("Workflow {0} is not running to be stopped.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

await client.StopWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
Expand All @@ -113,7 +113,7 @@ async void Action(Options o)
if (!workflow.IsPaused)
{
Console.WriteLine("Workflow {0} is not suspended to be resumed.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

await client.ResumeWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
Expand All @@ -124,7 +124,7 @@ async void Action(Options o)
if (!workflow.IsWaitingForApproval)
{
Console.WriteLine("Workflow {0} is not waiting for approval to be approved.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

await client.ApproveWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
Expand All @@ -135,15 +135,18 @@ async void Action(Options o)
if (!workflow.IsWaitingForApproval)
{
Console.WriteLine("Workflow {0} is not waiting for approval to be rejected.", o.WorkflowId);
return;
return await Task.FromResult(1);
}

await client.RejectWorkflow(o.WorkflowId, Guid.Parse(o.JobId), username, password);
break;
}

return await Task.FromResult(0);
}

var res = parser.ParseArguments<Options>(args).WithParsed(Action);
var res = parser.ParseArguments<Options>(args);
_ = await res.MapResult(ExecuteCommand, _ => Task.FromResult(1));

_ = res.WithNotParsed(_ =>
{
Expand Down

0 comments on commit 5dde26c

Please sign in to comment.