Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created December 6, 2023 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/5c4f18e98607bad2f81230bdcb422932 to your computer and use it in GitHub Desktop.
Save chuongmep/5c4f18e98607bad2f81230bdcb422932 to your computer and use it in GitHub Desktop.
public async Task<Status> ExecuteWorkItem(string token, string projectId, string versionId,string modelName, string callBackUrl)
{
Console.WriteLine("ActivityId: " + _configuration.ActivityFullName);
dynamic downloadUrl = await BuildDownloadURL(token, projectId, versionId).ConfigureAwait(false);
Console.WriteLine("Download URL: " + downloadUrl.Url);
XrefTreeArgument treeArgument = await BuildUploadURL(token).ConfigureAwait(false);
Console.WriteLine("TreeArgument: " + treeArgument.Url);
WorkItem workItemSpec = new WorkItem()
{
ActivityId = _configuration.ActivityFullName,
Arguments = new Dictionary<string, IArgument>()
{
{"inputFile", downloadUrl},
{"result", treeArgument},
{"onComplete", new XrefTreeArgument {Verb = Verb.Post, Url = callBackUrl}}
},
LimitProcessingTimeSec = 3600,
};
Console.WriteLine("Start Create WorkItem");
WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec).ConfigureAwait(false);
Console.WriteLine("WorkItemStatus: " + workItemStatus.Status);
Console.WriteLine("Working Item Id: " + workItemStatus.Id);
// wait until the work item is finished
Status status = default;
while (!workItemStatus.Status.IsDone())
{
await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false);
workItemStatus = await _designAutomation.GetWorkitemStatusAsync(workItemStatus.Id).ConfigureAwait(false);
Console.WriteLine("WorkItemStatus: " + workItemStatus.Status);
Console.WriteLine("Result:" + workItemStatus.ReportUrl);
status = workItemStatus.Status;
}
// get number after ?version=
string version = versionId.Split("=")[1];
string downloadOutput = DownloadOutput(version,token,treeArgument);
return status;
//UploadFile(downloadOutput,modelName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment