public static async Task <string> WriteRecordsToBlob( [ActivityTrigger] ActivityCreateBlobInfo info, Binder binder, ILogger log) { string outputLocation = $"{info.BlobContainer}/{info.BlobName}"; List <FakeDTO> list = PopulateFakeData(info); log.LogInformation($"[INFO] Started from '{info.NumberToStart} to get {info.NumberOfRecords} records'"); log.LogInformation($"[INFO] Writing to '{outputLocation}'"); // write contents into a blob JsonSerializer serializer = new JsonSerializer(); try { using (TextWriter outputWriter = await binder.BindAsync <TextWriter>( new BlobAttribute(outputLocation, FileAccess.Write))) { serializer.Serialize(outputWriter, list); } } catch (Exception ex) { log.LogInformation($"Error : '{ex.Message}'"); } return(outputLocation); }
private static List <FakeDTO> PopulateFakeData(ActivityCreateBlobInfo info) { var list = new List <FakeDTO>(); for (int i = info.NumberToStart; i < info.NumberToStart + info.NumberOfRecords; i++) { list.Add(new FakeDTO() { SeqID = Guid.NewGuid().ToString(), Name = "Name" + i.ToString(), TopValue = "Top" + i.ToString(), BottomValue = "Bottom" + i.ToString() }); } return(list); }
public static async Task <string> Run( [OrchestrationTrigger] DurableOrchestrationContext context) { string result = string.Empty; string requestID = context.GetInput <string>()?.Trim(); if (string.IsNullOrEmpty(requestID)) { requestID = Guid.NewGuid().ToString(); } var actvityInfo = new ActivityCreateBlobInfo() { BlobContainer = requestID, NumberOfRecords = 100, }; int loopCount = 10; var tasks = new List <Task <string> >(); for (int i = 0; i < loopCount; i++) { actvityInfo.BlobName = $"{i+1}.json"; actvityInfo.NumberToStart = i * actvityInfo.NumberOfRecords + 1; tasks.Add( context.CallActivityAsync <string>( "WriteRecordsToBlob", actvityInfo) ); } //case using WhenAll string[] results = await Task.WhenAll(tasks); //.ConfigureAwait(false); 사용하면 안됨. // 기본값 true로 해서 SynchronizationContext로 동기화하지 않는다면, 끝났다는 정보를 API가 제공하지 못함. // 즉, 실행이 끝났는대도 API는 running을 알려주게 됨. result = JsonConvert.SerializeObject(results); return(result); }