private static async Task UpdateTaskStatus()

in ProcessManager/BackendQueueProcessor/BackendQueueProcessor.cs [83:133]


        private static async Task UpdateTaskStatus(string taskId, string backendUri, string taskBody, string statusDetail, string backendStatus, AppInsightsLogger appInsightsLogger)
        {
            IDatabase db = null;
            try
            {
                db = RedisConnection.GetDatabase();
            }
            catch (Exception ex)
            {
                appInsightsLogger.LogError(ex, URL, taskId);
            }

            RedisValue storedStatus = RedisValue.Null;
            try
            {
                storedStatus = await db.StringGetAsync(taskId);
            }
            catch (Exception ex)
            {
                appInsightsLogger.LogError(ex, URL, taskId);
            }

            APITask task = null;
            if (storedStatus.HasValue)
            {
                task = JsonConvert.DeserializeObject<APITask>(storedStatus.ToString());
                task.Status = statusDetail;
                task.Timestamp = DateTime.UtcNow.ToString();
            }
            else
            {
                appInsightsLogger.LogWarning("Cannot find status in cache", URL, taskId);

                task = new APITask()
                {
                    TaskId = Guid.NewGuid().ToString(),
                    Status = statusDetail,
                    BackendStatus = backendStatus,
                    Body = taskBody,
                    Timestamp = DateTime.UtcNow.ToString(),
                    Endpoint = task.Endpoint,
                    PublishToGrid = true
                };
            }

            if (await db.StringSetAsync(task.TaskId, JsonConvert.SerializeObject(task)) == false)
            {
                var ex = new Exception("Unable to complete redis transaction.");
                appInsightsLogger.LogError(ex, task.Endpoint, task.TaskId);
            }
        }