public PollingWatermark(PollingWatermarkEntity pollingWatermarkEntity) { SourceSystem = pollingWatermarkEntity.PartitionKey; Entity = pollingWatermarkEntity.RowKey; DateTime currentPollingDateTime = DateTime.Now.ToUniversalTime(); Watermark = pollingWatermarkEntity.Watermark; NextWatermark = currentPollingDateTime; }
public static async Task <HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) { log.Info($"GetPollingWatermark Function is processing a request."); try { // Get request body PollingWatermark currentPollingWatermark = await req.Content.ReadAsAsync <PollingWatermark>(); // If required properties not provided correctly in the JSON body, return BadRequest if (currentPollingWatermark.SourceSystem == null || currentPollingWatermark.Entity == null || currentPollingWatermark.NextWatermark == DateTime.MinValue) { return(req.CreateResponse(HttpStatusCode.BadRequest, "Invalid request body")); } //Retrieve the current PollingWatermark Entity based on the provided SourceSystem and Entity properties CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("PollingWatermarkStorage")); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("PollingWatermark"); TableOperation retrieveOperation = TableOperation.Retrieve <PollingWatermarkEntity>(currentPollingWatermark.SourceSystem, currentPollingWatermark.Entity); TableResult retrievedResult = table.Execute(retrieveOperation); PollingWatermarkEntity pollingWatermarkToUpdate = (PollingWatermarkEntity)retrievedResult.Result; if (pollingWatermarkToUpdate != null) { // Update the Entity pollingWatermarkToUpdate.Watermark = currentPollingWatermark.NextWatermark; TableOperation updateOperation = TableOperation.Replace(pollingWatermarkToUpdate); table.Execute(updateOperation); return(req.CreateResponse(HttpStatusCode.OK)); } else { // If Polling Watermark to update for the provided SourceSystem and Entity is not found, return NotFound return(req.CreateResponse(HttpStatusCode.NotFound, string.Format("Polling watermark to update not found. SourceSystem: '{0}', Entity: '{1}'.", currentPollingWatermark.SourceSystem, currentPollingWatermark.Entity))); } } catch (Exception ex) { return(req.CreateResponse(HttpStatusCode.InternalServerError)); } }