private static async Task PublishEventGridEvent()

in ProcessManager/CacheManager/CacheConnectorUpsert.cs [234:261]


        private static async Task<bool> PublishEventGridEvent(APITask task, string taskBody, string eventGridTopicUri, string eventGridKey, AppInsightsLogger appInsightsLogger)
        {
            var ev = new EventGridEvent()
            {
                Id = task.TaskId,
                EventType = "task",
                Data = taskBody,
                EventTime = DateTime.Parse(task.Timestamp),
                Subject = task.Endpoint,
                DataVersion = "1.0"
            };

            string topicHostname = new Uri(eventGridTopicUri).Host;
            TopicCredentials topicCredentials = new TopicCredentials(eventGridKey);
            EventGridClient client = new EventGridClient(topicCredentials);

            try
            {
                await client.PublishEventsAsync(topicHostname, new List<EventGridEvent>() { ev });
            }
            catch (Exception ex)
            {
                appInsightsLogger.LogError(ex, task.Endpoint, task.TaskId);
                return false;
            }

            return true;
        }