private async Task ExecuteMainJob() { var apiListResponse = networkManager.Request(config.ApiListEndPoint, config.ApiListResource, RestSharp.Method.GET, config.DefaultConnectionTimeout, null, null).CheckResponse(); LogManager.Write(true, "Retreiving API List..."); List <Task> taskList = new List <Task>(); if (apiListResponse.IsValid) { LogManager.Write(true, "Retreiving API List... Success!"); var apiScheduleList = APIListItem.FromJson(apiListResponse.Content); if ((apiScheduleList != null) && apiScheduleList.Count > 0) { LogManager.Write(true, $"{apiScheduleList.Count.ToString("00")} API's found."); var tasks = apiScheduleList.Select(s => FireModule(s)).ToArray(); await Task.WhenAll(tasks); } else { LogManager.Write(false, $"No API's found."); } } }
private async Task FireModule(APIListItem item) { LogManager.Write(true, $"Fire Module [{item.ApiName}]..."); var nextRun = item.LastRun.AddMilliseconds(item.TimeInterval); if (nextRun <= DateTime.Now) { var itemResponse = await networkManager.RequestAsync(item.EndPoint, item.Resource, item.Method, item.TimeOut, item.Paramters, item.ApiName); var checkResponse = itemResponse.CheckResponse(); if (checkResponse.IsValid) { Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("ApiName", item.ApiName); dict.Add("LastRun", nextRun); var apiUpdateResponse = networkManager.Request(config.ApiListEndPoint, config.ApiUpdateResource, RestSharp.Method.POST, config.DefaultConnectionTimeout, dict, null).CheckResponse(); if (apiUpdateResponse.IsValid) { LogManager.Write(true, $"Module [{item.ApiName}] SUCCESS."); } } else { LogManager.Write(true, $"Module [{item.ApiName}] ERROR."); } } }