Added RunSatelliteTask to GeneralService

This commit is contained in:
Riepma 2020-10-12 16:59:23 +02:00
parent ecfc76105f
commit 92a8e0d68f

View File

@ -268,5 +268,49 @@ namespace FarmmapsApi.Services
return shadowItem; return shadowItem;
} }
public async Task<Item> RunSatelliteTask(Item cropfieldItem)
{
var taskmapRequest = new TaskRequest { TaskType = SATELLITE_TASK };
string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(cropfieldItem.Code, taskmapRequest);
await PollTask(TimeSpan.FromSeconds(5), async (tokenSource) =>
{
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
_logger.LogInformation($"Waiting on collection satellite data; status: {itemTaskStatus.State}");
if (itemTaskStatus.IsFinished)
tokenSource.Cancel();
});
var itemTask = await _farmmapsApiService.GetTaskStatusAsync(cropfieldItem.Code, itemTaskCode);
if (itemTask.State == ItemTaskState.Error)
{
_logger.LogError($"Something went wrong with task execution: {itemTask.Message}");
return null;
}
//the satellite item is a child of the cropfield
var itemName = "satellite";
var satelliteItem = await FindChildItemAsync(cropfieldItem.Code,
TEMPORAL_ITEMTYPE, itemName);
if (satelliteItem == null)
{
_logger.LogError("Could not find the satellite data as a child item under the cropfield");
return null;
}
// geotiffs can be found as a item of children under the satellite item
var allSatelliteItems = await _farmmapsApiService.GetItemChildrenAsync(satelliteItem.Code);
var lastSatItem = allSatelliteItems[^1];
return lastSatItem;
}
} }
} }