Fixed uploading internal server error caused by timeout caused by too many request.
This commit is contained in:
@@ -40,6 +40,7 @@ namespace FarmmapsApi.Services
|
||||
|
||||
public async Task<Item> UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName)
|
||||
{
|
||||
|
||||
var startUpload = DateTime.UtcNow;
|
||||
var result = await _farmmapsApiService.UploadFile(filePath, root.Code,
|
||||
progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}"));
|
||||
@@ -47,28 +48,29 @@ namespace FarmmapsApi.Services
|
||||
if (result.Progress.Status == UploadStatus.Failed)
|
||||
return null;
|
||||
|
||||
var zipName = Path.GetFileNameWithoutExtension(filePath);
|
||||
var zipName = Path.GetFileName(filePath);
|
||||
Item shapeItem = null;
|
||||
await PollTask(TimeSpan.FromSeconds(3), async source =>
|
||||
{
|
||||
var uploadedFilesChildren = await _farmmapsApiService.GetItemChildrenAsync(root.Code);
|
||||
var zipItems = uploadedFilesChildren.Where(i => i.Name.Contains(zipName));
|
||||
var childrenTasks = new List<Task<List<Item>>>();
|
||||
|
||||
foreach (var zipItem in zipItems)
|
||||
{
|
||||
childrenTasks.Add(_farmmapsApiService.GetItemChildrenAsync(zipItem.Code,
|
||||
SHAPE_PROCESSED_ITEMTYPE));
|
||||
}
|
||||
|
||||
List<Item>[] items = await Task.WhenAll(childrenTasks);
|
||||
if (items.Length > 0)
|
||||
{
|
||||
var flatItems = items.SelectMany(i => i).Where(i => i.Name.Contains(itemName)).ToList();
|
||||
if (flatItems.Count > 0)
|
||||
List<Item> items = await _farmmapsApiService.GetItemChildrenAsync(zipItem.Code,
|
||||
SHAPE_PROCESSED_ITEMTYPE);
|
||||
|
||||
if (items.Count(i => i.Created >= startUpload) > 0)
|
||||
{
|
||||
shapeItem = flatItems.Where(i => i.Created >= startUpload).OrderByDescending(i => i.Created)
|
||||
shapeItem = items.Where(i => i.Name.Contains(itemName))
|
||||
.OrderByDescending(i => i.Created)
|
||||
.First();
|
||||
source.Cancel();
|
||||
|
||||
if(shapeItem != null)
|
||||
{
|
||||
source.Cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -76,18 +78,18 @@ namespace FarmmapsApi.Services
|
||||
return shapeItem;
|
||||
}
|
||||
|
||||
public async Task<Item> ShapeToGeotiff(Item shapeItemCode)
|
||||
public async Task<Item> ShapeToGeotiff(Item shapeItem)
|
||||
{
|
||||
var shapeToGeotiffRequest = new TaskRequest()
|
||||
{
|
||||
TaskType = "vnd.farmmaps.task.shapetogeotiff"
|
||||
};
|
||||
var taskCode = await _farmmapsApiService.QueueTaskAsync(shapeItemCode.Code, shapeToGeotiffRequest);
|
||||
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(shapeItemCode.Code, taskCode);
|
||||
var itemTaskStatus = await _farmmapsApiService.GetTaskStatusAsync(shapeItem.Code, taskCode);
|
||||
if (itemTaskStatus.IsFinished)
|
||||
tokenSource.Cancel();
|
||||
});
|
||||
@@ -95,8 +97,8 @@ namespace FarmmapsApi.Services
|
||||
_logger.LogInformation("Data shape converted to geotiff");
|
||||
|
||||
// the parent of the shape item is now the tiff item
|
||||
shapeItemCode = await _farmmapsApiService.GetItemAsync(shapeItemCode.Code);
|
||||
return await _farmmapsApiService.GetItemAsync(shapeItemCode.ParentCode);
|
||||
shapeItem = await _farmmapsApiService.GetItemAsync(shapeItem.Code);
|
||||
return await _farmmapsApiService.GetItemAsync(shapeItem.ParentCode);
|
||||
}
|
||||
|
||||
public async Task<Item> FindChildItemAsync(string parentCode, string itemType, string containsName,
|
||||
|
Reference in New Issue
Block a user