Created
July 31, 2017 07:54
-
-
Save sommereder/d55d0fed403bf1e788418acc5f7f407d to your computer and use it in GitHub Desktop.
Task Runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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