diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 679b2d9..624be47 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -96,27 +96,37 @@ namespace FarmmapsApi.Services public async Task ShapeToGeotiff(Item shapeItem) { - var shapeToGeotiffRequest = new TaskRequest() - { - TaskType = "vnd.farmmaps.task.shapetogeotiff" - }; - var taskCode = await _farmmapsApiService.QueueTaskAsync(shapeItem.Code, shapeToGeotiffRequest); - - await PollTask(TimeSpan.FromSeconds(3), async (tokenSource) => - { - _logger.LogInformation("Checking shapetogeotiff task status"); - var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(shapeItem.Code, taskCode); - if (itemTaskStatus.IsFinished) - tokenSource.Cancel(); - }); - - _logger.LogInformation("Data shape converted to geotiff"); + await RunAndWaitForTask(shapeItem, "vnd.farmmaps.task.shapetogeotiff"); // the parent of the shape item is now the tiff item shapeItem = await _farmmapsApiService.GetItemAsync(shapeItem.Code); return await _farmmapsApiService.GetItemAsync(shapeItem.ParentCode); } + public async Task RunAndWaitForTask(Item subjectItem, string taskIdentifier, + Action configureCallback = null, int retrySeconds = 3) + { + var taskRequest = new TaskRequest() + { + TaskType = taskIdentifier + }; + configureCallback?.Invoke(taskRequest); + + var taskCode = await _farmmapsApiService.QueueTaskAsync(subjectItem.Code, taskRequest); + + await PollTask(TimeSpan.FromSeconds(retrySeconds), async (tokenSource) => + { + _logger.LogInformation($"Checking {taskIdentifier} task status"); + var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(subjectItem.Code, taskCode); + if (itemTaskStatus.IsFinished) + tokenSource.Cancel(); + }); + + _logger.LogInformation($"{taskIdentifier} finished"); + + return await _farmmapsApiService.GetTaskStatusAsync(subjectItem.Code, taskCode); + } + public async Task FindChildItemAsync(string parentCode, string itemType, string containsName, Func filter = null, int maxTries = 10) { diff --git a/FarmmapsHaulmkilling/HaulmkillingApplication.cs b/FarmmapsHaulmkilling/HaulmkillingApplication.cs index bfb87ed..44af239 100644 --- a/FarmmapsHaulmkilling/HaulmkillingApplication.cs +++ b/FarmmapsHaulmkilling/HaulmkillingApplication.cs @@ -61,9 +61,14 @@ namespace FarmmapsHaulmkilling @"{""type"":""Polygon"",""coordinates"":[[[4.617786844284247,52.22533706956424],[4.618642601314543,52.225938364585989],[4.6192153806397,52.22563988897754],[4.619192414656403,52.2256242822442],[4.620306732153958,52.225031745661528],[4.620542019225217,52.22519855319158],[4.621157509147853,52.22487436515405],[4.623387917230182,52.22367660757213],[4.624563444939009,52.22304740241544],[4.624562779355982,52.223046635247019],[4.624534908813479,52.22302596787506],[4.627873021330343,52.221240670658399],[4.627504935938338,52.220104419135129],[4.627324878706837,52.22020569669098],[4.627320696113512,52.22020660117888],[4.626707169518044,52.22053923770041],[4.624700376420229,52.221619047547488],[4.623471571183885,52.22227447969577],[4.623471511010673,52.22227500174403],[4.623468838689317,52.22228052566992],[4.617786844284247,52.22533706956424]]]}"); // run satellite task on just added cropfield - - + _logger.LogInformation("Gathering satellite information for cropfield, this might take a while!"); + await _generalService.RunAndWaitForTask(cropfieldItem, "vnd.farmmaps.task.satellite"); + // find ndvi or wdvi satellite data geotiffs + + // create haulmkilling application map + + // download application map } } } \ No newline at end of file