Skip to content

Instantly share code, notes, and snippets.

@sommereder
Created July 31, 2017 07:54
Show Gist options
  • Save sommereder/d55d0fed403bf1e788418acc5f7f407d to your computer and use it in GitHub Desktop.
Save sommereder/d55d0fed403bf1e788418acc5f7f407d to your computer and use it in GitHub Desktop.
Task Runner
public string RunTasksAndGetResponse(int pNumTasks = 0)
{
if (mRequestJson != null && mResponseJson != null) // check for necessary files
{
string lResponseString = "{\"ActionResult\":{\"Result\": \"ERROR: Timeout reached while executing eggPlant task(s).\",\"Expected\":[],\"Received\":[],\"Screenshots\":[]}}";
Stopwatch lRequestStopwatch = Stopwatch.StartNew();
TimeSpan lRequestTimeout = TimeSpan.FromSeconds((pNumTasks > 1 ? 5 : 10) * 60 * pNumTasks);
string lCampaignId = CreateCampaign(mRequestJson, mResponseJson); // create campaign by requesting the API
string lCampaignStatus = GetCampaignStatus(lCampaignId); // update campaign status
while (lCampaignStatus != "finished" && lRequestStopwatch.Elapsed < lRequestTimeout) // while campaign not finished and timeout not reached
{
Console.WriteLine(lRequestStopwatch);
lCampaignStatus = GetCampaignStatus(lCampaignId); // update campaign status
Thread.Sleep(5 * 1000); // rest for five seconds
}
if (lCampaignStatus == "finished")
{
SaveCampaignResult(lCampaignId, mTargetFolder); // save campaign results into target folder
lResponseString = SeparateResultFilesAndGetResponse(); // separate result and return response file as string
}
return lResponseString;
}
return null; // return null if not all requirements are met
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment