Я пытаюсь дождаться внешнего события в функции суборкестратора. Тест показывает, что событие, отправленное на основной идентификатор оркестратора, может быть получено в основном оркестраторе, но не в подчиненном оркестраторе.
Я предположил, что события не принимаются, потому что они отправляются на идентификатор экземпляра основного оркестратора, но если Я хочу отправить даже идентификатор экземпляра суборкестратора, но не вижу простого способа выяснить, что такое идентификатор экземпляра суборкестратора. В изолированной модели TaskOrchestrationContext не предлагает передачу идентификатора экземпляра функции запуска суборкестратора. Я предполагаю, что после запуска функции суборкестратора она может отправить событие главному оркестратору со своим идентификатором, но это выглядит странной и запутанной реализацией.
Приведенный ниже код предоставляет Jobs_HttpStart_Event для запуска отправки событий оркестратором.< /p>
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;
namespace DurableFuncExperiment
{
public static class Function
{
public record EventData(string instanceId, string eventName, string data);
public const string SayHelloOrchestrator = "Jobs_SayHello";
public const string SayHelloOneActivitity = "Jobs_SayHelloOne";
public const string SayHelloEventOrchestrator = "Jobs_SayHelloEventOrchestrator";
public const string SayHelloEventSubOrchestrator = "Jobs_SayHelloEventSubOrchestrator";
// Leave SayHello for experiments if needed
[Function(SayHelloOrchestrator)]
public static async Task RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation("Saying hello.");
var outputs = new List();
// Replace name and input with values relevant for your Durable Functions Activity
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "Tokyo"));
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "Seattle"));
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
const string EventName = "EventToWaitFor";
[Function(SayHelloEventOrchestrator)]
public static async Task RunSayHelloEventOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context,
[DurableClient] DurableTaskClient durableTaskClient)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation("Saying hello.");
var outputs = new List();
// Replace name and input with values relevant for your Durable Functions Activity
var task = context.CallSubOrchestratorAsync(SayHelloEventSubOrchestrator);
await context.CreateTimer(TimeSpan.FromSeconds(15), CancellationToken.None);
await context.CallActivityAsync(nameof(RaiseEventActivity), new EventData(context.InstanceId, EventName, "Data"));
await context.CallActivityAsync(nameof(RaiseEventActivity), new EventData(context.InstanceId, EventName, "Data"));
var eventValue = await context.WaitForExternalEvent(EventName);
logger.LogInformation($"Event received by main orchestration: {eventValue}");
await task;
logger.LogInformation($"Sub orchestration finished and was awaited succesfully");
return outputs;
}
[Function(SayHelloEventSubOrchestrator)]
public static async Task RunSayHelloEventSubOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation($"RunSayHelloEventSubOrchestrator started. InstanceId={context.InstanceId}");
var outputs = new List();
var eventValue = await context.WaitForExternalEvent(EventName);
logger.LogInformation($"Event received by sub orchestration: {eventValue}");
return outputs;
}
[Function(nameof(SayHelloOneActivitity))]
public static string SayHelloOne([ActivityTrigger] string name, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("SayHello");
logger.LogInformation("Saying hello to {name}.", name);
return $"Hello {name}!";
}
[Function(nameof(RaiseEventActivity))]
public static async Task RaiseEventActivity([ActivityTrigger] EventData eventData, [DurableClient] DurableTaskClient client, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("RaiseEventActivity");
logger.LogInformation($"raising event {eventData}");
await client.RaiseEventAsync(instanceId: eventData.instanceId, eventName: eventData.eventName, eventPayload: eventData.data);
}
[Function("Jobs_HttpStart_Event")]
public static async Task Jobs_HttpStart_Event(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("Jobs_HttpStart_Event");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
SayHelloEventOrchestrator);
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft.com/azure/azure ... hestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
}
}
Журнал заканчивается, когда главный оркестратор получает событие. Суборкестратор зависает навсегда.
For detailed output, run func with --verbose flag.
[2024-07-02T04:06:42.063Z] Host lock lease acquired by instance ID '0000000000000000000000000C75A72E'.
[2024-07-02T04:06:51.223Z] Executing 'Functions.Jobs_HttpStart_Event' (Reason='This function was programmatically called via the host APIs.', Id=86ba1f8b-9454-4158-9e7a-d1316a7a1140)
[2024-07-02T04:06:51.858Z] Scheduling new Jobs_SayHelloEventOrchestrator orchestration with instance ID 'd0e8390352d1403b88e6fb763a33cbb2' and 0 bytes of input data.
[2024-07-02T04:06:52.116Z] Started orchestration with ID = 'd0e8390352d1403b88e6fb763a33cbb2'.
[2024-07-02T04:06:52.239Z] Executed 'Functions.Jobs_HttpStart_Event' (Succeeded, Id=86ba1f8b-9454-4158-9e7a-d1316a7a1140, Duration=1056ms)
[2024-07-02T04:06:52.272Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=91ac3cd9-504b-4a6e-81f4-b55a4febdcc2)
[2024-07-02T04:06:52.507Z] Saying hello.
[2024-07-02T04:06:52.587Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=91ac3cd9-504b-4a6e-81f4-b55a4febdcc2, Duration=341ms)
[2024-07-02T04:06:52.729Z] Executing 'Functions.Jobs_SayHelloEventSubOrchestrator' (Reason='(null)', Id=52250685-de55-4753-9eb5-a119bb2f14c1)
[2024-07-02T04:06:52.768Z] RunSayHelloEventSubOrchestrator started. InstanceId=2236b5d8ffd15b7b9180de5d977309da
[2024-07-02T04:06:52.781Z] Executed 'Functions.Jobs_SayHelloEventSubOrchestrator' (Succeeded, Id=52250685-de55-4753-9eb5-a119bb2f14c1, Duration=54ms)
[2024-07-02T04:07:08.919Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=cf21b5f6-0582-4f7e-bfe8-bd7d2fe10fef)
[2024-07-02T04:07:08.979Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=cf21b5f6-0582-4f7e-bfe8-bd7d2fe10fef, Duration=61ms)
[2024-07-02T04:07:09.023Z] Executing 'Functions.RaiseEventActivity' (Reason='(null)', Id=afdcb70b-6f35-4b1e-a87d-72929ac86192)
[2024-07-02T04:07:09.041Z] raising event EventData { instanceId = d0e8390352d1403b88e6fb763a33cbb2, eventName = EventToWaitFor, data = Data }
[2024-07-02T04:07:09.100Z] Executed 'Functions.RaiseEventActivity' (Succeeded, Id=afdcb70b-6f35-4b1e-a87d-72929ac86192, Duration=81ms)
[2024-07-02T04:07:09.115Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=71444a03-da20-4325-b60f-dba7bfe5b86e)
[2024-07-02T04:07:09.149Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=71444a03-da20-4325-b60f-dba7bfe5b86e, Duration=36ms)
[2024-07-02T04:07:09.203Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=81b80312-48f0-4aba-8d42-4a9fd384966b)
[2024-07-02T04:07:09.238Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=81b80312-48f0-4aba-8d42-4a9fd384966b, Duration=35ms)
[2024-07-02T04:07:09.264Z] Executing 'Functions.RaiseEventActivity' (Reason='(null)', Id=e8417808-7b31-41fc-bdbc-87358e714c9b)
[2024-07-02T04:07:09.286Z] raising event EventData { instanceId = d0e8390352d1403b88e6fb763a33cbb2, eventName = EventToWaitFor, data = Data }
[2024-07-02T04:07:09.334Z] Executed 'Functions.RaiseEventActivity' (Succeeded, Id=e8417808-7b31-41fc-bdbc-87358e714c9b, Duration=70ms)
[2024-07-02T04:07:09.352Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=44627a58-4494-4099-a5b5-435bf1a4b994)
[2024-07-02T04:07:09.373Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=44627a58-4494-4099-a5b5-435bf1a4b994, Duration=20ms)
[2024-07-02T04:07:12.545Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=9b3d7f92-a6fe-4ffb-b072-8fbca7a03c6f)
[2024-07-02T04:07:12.561Z] Event received by main orchestration: Data
[2024-07-02T04:07:12.567Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=9b3d7f92-a6fe-4ffb-b072-8fbca7a03c6f, Duration=22ms)
Подробнее здесь: https://stackoverflow.com/questions/786 ... ated-model
Невозможно получать события в функции устойчивого суборкестратора (изолированная модель) ⇐ C#
Место общения программистов C#
1729372385
Anonymous
Я пытаюсь дождаться внешнего события в функции суборкестратора. Тест показывает, что событие, отправленное на основной идентификатор оркестратора, может быть получено в основном оркестраторе, но не в подчиненном оркестраторе.
Я предположил, что события не принимаются, потому что они отправляются на идентификатор экземпляра основного оркестратора, но если Я хочу отправить даже идентификатор экземпляра суборкестратора, но не вижу простого способа выяснить, что такое идентификатор экземпляра суборкестратора. В изолированной модели TaskOrchestrationContext не предлагает передачу идентификатора экземпляра функции запуска суборкестратора. Я предполагаю, что после запуска функции суборкестратора она может отправить событие главному оркестратору со своим идентификатором, но это выглядит странной и запутанной реализацией.
Приведенный ниже код предоставляет Jobs_HttpStart_Event для запуска отправки событий оркестратором.< /p>
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;
namespace DurableFuncExperiment
{
public static class Function
{
public record EventData(string instanceId, string eventName, string data);
public const string SayHelloOrchestrator = "Jobs_SayHello";
public const string SayHelloOneActivitity = "Jobs_SayHelloOne";
public const string SayHelloEventOrchestrator = "Jobs_SayHelloEventOrchestrator";
public const string SayHelloEventSubOrchestrator = "Jobs_SayHelloEventSubOrchestrator";
// Leave SayHello for experiments if needed
[Function(SayHelloOrchestrator)]
public static async Task RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation("Saying hello.");
var outputs = new List();
// Replace name and input with values relevant for your Durable Functions Activity
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "Tokyo"));
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "Seattle"));
outputs.Add(await context.CallActivityAsync(SayHelloOneActivitity, "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
const string EventName = "EventToWaitFor";
[Function(SayHelloEventOrchestrator)]
public static async Task RunSayHelloEventOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context,
[DurableClient] DurableTaskClient durableTaskClient)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation("Saying hello.");
var outputs = new List();
// Replace name and input with values relevant for your Durable Functions Activity
var task = context.CallSubOrchestratorAsync(SayHelloEventSubOrchestrator);
await context.CreateTimer(TimeSpan.FromSeconds(15), CancellationToken.None);
await context.CallActivityAsync(nameof(RaiseEventActivity), new EventData(context.InstanceId, EventName, "Data"));
await context.CallActivityAsync(nameof(RaiseEventActivity), new EventData(context.InstanceId, EventName, "Data"));
var eventValue = await context.WaitForExternalEvent(EventName);
logger.LogInformation($"Event received by main orchestration: {eventValue}");
await task;
logger.LogInformation($"Sub orchestration finished and was awaited succesfully");
return outputs;
}
[Function(SayHelloEventSubOrchestrator)]
public static async Task RunSayHelloEventSubOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(SayHelloOrchestrator);
logger.LogInformation($"RunSayHelloEventSubOrchestrator started. InstanceId={context.InstanceId}");
var outputs = new List();
var eventValue = await context.WaitForExternalEvent(EventName);
logger.LogInformation($"Event received by sub orchestration: {eventValue}");
return outputs;
}
[Function(nameof(SayHelloOneActivitity))]
public static string SayHelloOne([ActivityTrigger] string name, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("SayHello");
logger.LogInformation("Saying hello to {name}.", name);
return $"Hello {name}!";
}
[Function(nameof(RaiseEventActivity))]
public static async Task RaiseEventActivity([ActivityTrigger] EventData eventData, [DurableClient] DurableTaskClient client, FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("RaiseEventActivity");
logger.LogInformation($"raising event {eventData}");
await client.RaiseEventAsync(instanceId: eventData.instanceId, eventName: eventData.eventName, eventPayload: eventData.data);
}
[Function("Jobs_HttpStart_Event")]
public static async Task Jobs_HttpStart_Event(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("Jobs_HttpStart_Event");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
SayHelloEventOrchestrator);
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
}
}
Журнал заканчивается, когда главный оркестратор получает событие. Суборкестратор зависает навсегда.
For detailed output, run func with --verbose flag.
[2024-07-02T04:06:42.063Z] Host lock lease acquired by instance ID '0000000000000000000000000C75A72E'.
[2024-07-02T04:06:51.223Z] Executing 'Functions.Jobs_HttpStart_Event' (Reason='This function was programmatically called via the host APIs.', Id=86ba1f8b-9454-4158-9e7a-d1316a7a1140)
[2024-07-02T04:06:51.858Z] Scheduling new Jobs_SayHelloEventOrchestrator orchestration with instance ID 'd0e8390352d1403b88e6fb763a33cbb2' and 0 bytes of input data.
[2024-07-02T04:06:52.116Z] Started orchestration with ID = 'd0e8390352d1403b88e6fb763a33cbb2'.
[2024-07-02T04:06:52.239Z] Executed 'Functions.Jobs_HttpStart_Event' (Succeeded, Id=86ba1f8b-9454-4158-9e7a-d1316a7a1140, Duration=1056ms)
[2024-07-02T04:06:52.272Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=91ac3cd9-504b-4a6e-81f4-b55a4febdcc2)
[2024-07-02T04:06:52.507Z] Saying hello.
[2024-07-02T04:06:52.587Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=91ac3cd9-504b-4a6e-81f4-b55a4febdcc2, Duration=341ms)
[2024-07-02T04:06:52.729Z] Executing 'Functions.Jobs_SayHelloEventSubOrchestrator' (Reason='(null)', Id=52250685-de55-4753-9eb5-a119bb2f14c1)
[2024-07-02T04:06:52.768Z] RunSayHelloEventSubOrchestrator started. InstanceId=2236b5d8ffd15b7b9180de5d977309da
[2024-07-02T04:06:52.781Z] Executed 'Functions.Jobs_SayHelloEventSubOrchestrator' (Succeeded, Id=52250685-de55-4753-9eb5-a119bb2f14c1, Duration=54ms)
[2024-07-02T04:07:08.919Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=cf21b5f6-0582-4f7e-bfe8-bd7d2fe10fef)
[2024-07-02T04:07:08.979Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=cf21b5f6-0582-4f7e-bfe8-bd7d2fe10fef, Duration=61ms)
[2024-07-02T04:07:09.023Z] Executing 'Functions.RaiseEventActivity' (Reason='(null)', Id=afdcb70b-6f35-4b1e-a87d-72929ac86192)
[2024-07-02T04:07:09.041Z] raising event EventData { instanceId = d0e8390352d1403b88e6fb763a33cbb2, eventName = EventToWaitFor, data = Data }
[2024-07-02T04:07:09.100Z] Executed 'Functions.RaiseEventActivity' (Succeeded, Id=afdcb70b-6f35-4b1e-a87d-72929ac86192, Duration=81ms)
[2024-07-02T04:07:09.115Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=71444a03-da20-4325-b60f-dba7bfe5b86e)
[2024-07-02T04:07:09.149Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=71444a03-da20-4325-b60f-dba7bfe5b86e, Duration=36ms)
[2024-07-02T04:07:09.203Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=81b80312-48f0-4aba-8d42-4a9fd384966b)
[2024-07-02T04:07:09.238Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=81b80312-48f0-4aba-8d42-4a9fd384966b, Duration=35ms)
[2024-07-02T04:07:09.264Z] Executing 'Functions.RaiseEventActivity' (Reason='(null)', Id=e8417808-7b31-41fc-bdbc-87358e714c9b)
[2024-07-02T04:07:09.286Z] raising event EventData { instanceId = d0e8390352d1403b88e6fb763a33cbb2, eventName = EventToWaitFor, data = Data }
[2024-07-02T04:07:09.334Z] Executed 'Functions.RaiseEventActivity' (Succeeded, Id=e8417808-7b31-41fc-bdbc-87358e714c9b, Duration=70ms)
[2024-07-02T04:07:09.352Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=44627a58-4494-4099-a5b5-435bf1a4b994)
[2024-07-02T04:07:09.373Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=44627a58-4494-4099-a5b5-435bf1a4b994, Duration=20ms)
[2024-07-02T04:07:12.545Z] Executing 'Functions.Jobs_SayHelloEventOrchestrator' (Reason='(null)', Id=9b3d7f92-a6fe-4ffb-b072-8fbca7a03c6f)
[2024-07-02T04:07:12.561Z] Event received by main orchestration: Data
[2024-07-02T04:07:12.567Z] Executed 'Functions.Jobs_SayHelloEventOrchestrator' (Succeeded, Id=9b3d7f92-a6fe-4ffb-b072-8fbca7a03c6f, Duration=22ms)
Подробнее здесь: [url]https://stackoverflow.com/questions/78695020/unable-to-receive-events-in-durable-suborchestrator-function-isolated-model[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия