master #8
@ -268,5 +268,49 @@ namespace FarmmapsApi.Services
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user