private IEnumerable <Submission> readSubmissions(bool retryOnFailed = true, HashSet <byte> compilers = null) { string endpoint = buildEndpoint("submissions"); string jsonSubmissions; List <Submission> submissions = null; TimeOutHelper time = new TimeOutHelper(); do { try { jsonSubmissions = client.GetStringAsync(endpoint).Result; JArray parsedSubmissions = JArray.Parse(jsonSubmissions); submissions = new List <Submission>(); logger.Debug("Returned {0} submissions", parsedSubmissions.Count); byte compilerId = 1; byte checkerCompilerId = 1; for (int i = 0; i < parsedSubmissions.Count; i++) { compilerId = (byte)parsedSubmissions[i]["compiler_id"]; checkerCompilerId = (byte)parsedSubmissions[i]["problem"]["checker_compiler_id"]; if (compilers is null || (compilers.Contains(compilerId) && compilers.Contains(checkerCompilerId))) { submissions.Add( new Submission( id: (ulong)parsedSubmissions[i]["id"], sourceUrl: (string)parsedSubmissions[i]["source_url"], compilerId: compilerId, checkerCompilerId: checkerCompilerId, problemId: (ulong)parsedSubmissions[i]["problem"]["id"], problemUpdatedAt: (DateTime)parsedSubmissions[i]["problem"]["updated_at"], memoryLimit: (UInt32)parsedSubmissions[i]["memory_limit"], timeLimit: (UInt32)parsedSubmissions[i]["time_limit"] ) ); } } logger.Debug("Selected {0} submissions", submissions.Count); break; } catch (Exception ex) { logger.Error(ex, "GetSubmissions failed with exception."); Thread.Sleep(time.GetTimeOut() * 1000); } } while (retryOnFailed); return(submissions); }
public bool SendRequest(RequestMessage message, bool retryOnFailed = true) { TimeOutHelper time = new TimeOutHelper(); do { try { var responseMessage = client.PostAsync(message.RequestUri, message.Data).Result; logger.Debug("Request {0} send {1}", message.RequestUri, responseMessage.StatusCode == HttpStatusCode.NoContent ? "successfully" : "failed"); if (responseMessage.StatusCode != HttpStatusCode.NoContent) { logger.Error("Request {0} server error message: {1}. Status code: {2}", message.RequestUri, responseMessage.Content?.ReadAsStringAsync()?.Result, responseMessage.StatusCode); } if (!retryOnFailed || responseMessage.StatusCode == HttpStatusCode.NoContent) { return(responseMessage.StatusCode == HttpStatusCode.NoContent); } } catch (HttpRequestException ex) { logger.Error(ex, "SendRequest failed with exception."); } Thread.Sleep(time.GetTimeOut() * 1000); } while (retryOnFailed); return(false); }