probeersel om een runKPItask te maken

This commit is contained in:
2023-03-31 11:02:06 +02:00
parent c79e0d062c
commit 7dda21dd77
5 changed files with 45 additions and 10 deletions

View File

@@ -27,5 +27,6 @@ namespace FarmmapsApiSamples
public const string SHADOW_TASK = "vnd.farmmaps.task.shadow";
public const string AHN_TASK = "vnd.farmmaps.task.ahn";
public const string WATBAL_TASK = "vnd.farmmaps.task.watbal";
public const string KPI_TASK = "vnd.farmmaps.task.kpi"; // dus nieuwe taak om de KPIs te berekenen
}
}

View File

@@ -277,6 +277,41 @@ namespace FarmmapsApi.Services
return bofekItem;
}
public async Task<Item> RunKPITask(Item cropfieldItem) // dit is dus nieuw om de KPI task te runnen
{
var taskmapRequest = new TaskRequest { TaskType = KPI_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 retreiving KPI 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;
}
//hier nog definieren waar in de hierarchie een KPI item is?
////the BOFEK data is a child of the cropfield
//var itemName = "bofek";
//var bofekItem = await FindChildItemAsync(cropfieldItem.Code,
// SHAPE_PROCESSED_ITEMTYPE, itemName);
//if (bofekItem == null)
//{
// _logger.LogError("Could not find the BOFEK data as a child item under the cropfield");
// return null;
//}
return bofekItem;
}
public async Task<Item> RunAhnTask(Item cropfieldItem) {
var taskmapRequest = new TaskRequest { TaskType = AHN_TASK };