@contember/engine-actions 2.1.0-rc.3 → 2.2.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +69 -0
- package/dist/development/index.cjs +24 -11
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +24 -11
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ActionsExecutionContainerHookFactory.cjs +5 -2
- package/dist/development/src/ActionsExecutionContainerHookFactory.cjs.map +1 -1
- package/dist/development/src/ActionsExecutionContainerHookFactory.js +5 -2
- package/dist/development/src/ActionsExecutionContainerHookFactory.js.map +1 -1
- package/dist/development/src/ActionsMetrics.cjs +98 -0
- package/dist/development/src/ActionsMetrics.cjs.map +1 -0
- package/dist/development/src/ActionsMetrics.js +98 -0
- package/dist/development/src/ActionsMetrics.js.map +1 -0
- package/dist/development/src/ListenerStoreProvider.cjs.map +1 -1
- package/dist/development/src/ListenerStoreProvider.js.map +1 -1
- package/dist/development/src/authorization/ActionsPermissionsFactory.cjs.map +1 -1
- package/dist/development/src/authorization/ActionsPermissionsFactory.js.map +1 -1
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.cjs.map +1 -1
- package/dist/development/src/dispatch/DispatchWorkerSupervisor.js.map +1 -1
- package/dist/development/src/dispatch/EventDispatcher.cjs +64 -23
- package/dist/development/src/dispatch/EventDispatcher.cjs.map +1 -1
- package/dist/development/src/dispatch/EventDispatcher.js +64 -23
- package/dist/development/src/dispatch/EventDispatcher.js.map +1 -1
- package/dist/development/src/dispatch/EventsRepository.cjs +49 -20
- package/dist/development/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/development/src/dispatch/EventsRepository.js +49 -20
- package/dist/development/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/development/src/dispatch/LazyDispatchWorker.cjs.map +1 -1
- package/dist/development/src/dispatch/LazyDispatchWorker.js.map +1 -1
- package/dist/development/src/dispatch/ProjectDispatcher.cjs +63 -21
- package/dist/development/src/dispatch/ProjectDispatcher.cjs.map +1 -1
- package/dist/development/src/dispatch/ProjectDispatcher.js +63 -21
- package/dist/development/src/dispatch/ProjectDispatcher.js.map +1 -1
- package/dist/development/src/dispatch/TargetHandlerResolver.cjs.map +1 -1
- package/dist/development/src/dispatch/TargetHandlerResolver.js.map +1 -1
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs +104 -4
- package/dist/development/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
- package/dist/development/src/dispatch/WebhookTargetHandler.js +104 -4
- package/dist/development/src/dispatch/WebhookTargetHandler.js.map +1 -1
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/graphql/http/ActionsApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/graphql/http/ActionsContextResolver.cjs.map +1 -1
- package/dist/development/src/graphql/http/ActionsContextResolver.js.map +1 -1
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/development/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -1
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs +68 -28
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -1
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js +68 -28
- package/dist/development/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -1
- package/dist/development/src/graphql/resolvers/ResolversFactory.cjs +1 -1
- package/dist/development/src/graphql/resolvers/ResolversFactory.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/ResolversFactory.js +1 -1
- package/dist/development/src/graphql/resolvers/ResolversFactory.js.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/RetryEventMutationResolver.js.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +1 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +1 -1
- package/dist/development/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/mutation/StopEventMutationResolver.js.map +1 -1
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs +1 -1
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js +1 -1
- package/dist/development/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -1
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs +1 -4
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -1
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js +1 -4
- package/dist/development/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -1
- package/dist/development/src/graphql/schema/actions.graphql.cjs +20 -8
- package/dist/development/src/graphql/schema/actions.graphql.cjs.map +1 -1
- package/dist/development/src/graphql/schema/actions.graphql.js +20 -8
- package/dist/development/src/graphql/schema/actions.graphql.js.map +1 -1
- package/dist/development/src/migrations/index.cjs.map +1 -1
- package/dist/development/src/migrations/index.js.map +1 -1
- package/dist/development/src/model/EventByIdQuery.cjs.map +1 -1
- package/dist/development/src/model/EventByIdQuery.js.map +1 -1
- package/dist/development/src/model/EventsInProcessingQuery.cjs.map +1 -1
- package/dist/development/src/model/EventsInProcessingQuery.js.map +1 -1
- package/dist/development/src/model/EventsToProcessQuery.cjs.map +1 -1
- package/dist/development/src/model/EventsToProcessQuery.js.map +1 -1
- package/dist/development/src/model/FailedEventsQuery.cjs.map +1 -1
- package/dist/development/src/model/FailedEventsQuery.js.map +1 -1
- package/dist/development/src/model/VariablesManager.cjs +54 -5
- package/dist/development/src/model/VariablesManager.cjs.map +1 -1
- package/dist/development/src/model/VariablesManager.js +54 -5
- package/dist/development/src/model/VariablesManager.js.map +1 -1
- package/dist/development/src/triggers/TriggerHandler.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerHandler.js.map +1 -1
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerIndirectChangesFetcher.js.map +1 -1
- package/dist/development/src/triggers/TriggerListenersBuilder.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerListenersBuilder.js.map +1 -1
- package/dist/development/src/triggers/TriggerListenersFactory.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerListenersFactory.js.map +1 -1
- package/dist/development/src/triggers/TriggerListenersStore.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerListenersStore.js.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadBuilder.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadBuilder.js.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadManager.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadManager.js.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadPersister.cjs +3 -1
- package/dist/development/src/triggers/TriggerPayloadPersister.cjs.map +1 -1
- package/dist/development/src/triggers/TriggerPayloadPersister.js +3 -1
- package/dist/development/src/triggers/TriggerPayloadPersister.js.map +1 -1
- package/dist/production/index.cjs +24 -11
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +24 -11
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ActionsExecutionContainerHookFactory.cjs +5 -2
- package/dist/production/src/ActionsExecutionContainerHookFactory.cjs.map +1 -1
- package/dist/production/src/ActionsExecutionContainerHookFactory.js +5 -2
- package/dist/production/src/ActionsExecutionContainerHookFactory.js.map +1 -1
- package/dist/production/src/ActionsMetrics.cjs +98 -0
- package/dist/production/src/ActionsMetrics.cjs.map +1 -0
- package/dist/production/src/ActionsMetrics.js +98 -0
- package/dist/production/src/ActionsMetrics.js.map +1 -0
- package/dist/production/src/ListenerStoreProvider.cjs.map +1 -1
- package/dist/production/src/ListenerStoreProvider.js.map +1 -1
- package/dist/production/src/authorization/ActionsPermissionsFactory.cjs.map +1 -1
- package/dist/production/src/authorization/ActionsPermissionsFactory.js.map +1 -1
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.cjs.map +1 -1
- package/dist/production/src/dispatch/DispatchWorkerSupervisor.js.map +1 -1
- package/dist/production/src/dispatch/EventDispatcher.cjs +64 -23
- package/dist/production/src/dispatch/EventDispatcher.cjs.map +1 -1
- package/dist/production/src/dispatch/EventDispatcher.js +64 -23
- package/dist/production/src/dispatch/EventDispatcher.js.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.cjs +49 -20
- package/dist/production/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.js +49 -20
- package/dist/production/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/production/src/dispatch/LazyDispatchWorker.cjs.map +1 -1
- package/dist/production/src/dispatch/LazyDispatchWorker.js.map +1 -1
- package/dist/production/src/dispatch/ProjectDispatcher.cjs +63 -21
- package/dist/production/src/dispatch/ProjectDispatcher.cjs.map +1 -1
- package/dist/production/src/dispatch/ProjectDispatcher.js +63 -21
- package/dist/production/src/dispatch/ProjectDispatcher.js.map +1 -1
- package/dist/production/src/dispatch/TargetHandlerResolver.cjs.map +1 -1
- package/dist/production/src/dispatch/TargetHandlerResolver.js.map +1 -1
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs +104 -4
- package/dist/production/src/dispatch/WebhookTargetHandler.cjs.map +1 -1
- package/dist/production/src/dispatch/WebhookTargetHandler.js +104 -4
- package/dist/production/src/dispatch/WebhookTargetHandler.js.map +1 -1
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/graphql/http/ActionsApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/graphql/http/ActionsContextResolver.cjs.map +1 -1
- package/dist/production/src/graphql/http/ActionsContextResolver.js.map +1 -1
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/production/src/graphql/http/ActionsGraphQLHandlerFactory.js.map +1 -1
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs +68 -28
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.cjs.map +1 -1
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js +68 -28
- package/dist/production/src/graphql/http/ActionsWebsocketControllerFactory.js.map +1 -1
- package/dist/production/src/graphql/resolvers/ResolversFactory.cjs +1 -1
- package/dist/production/src/graphql/resolvers/ResolversFactory.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/ResolversFactory.js +1 -1
- package/dist/production/src/graphql/resolvers/ResolversFactory.js.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.js.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/RetryEventMutationResolver.js.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs +1 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js +1 -1
- package/dist/production/src/graphql/resolvers/mutation/SetVariablesMutationResolver.js.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/mutation/StopEventMutationResolver.js.map +1 -1
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs +1 -1
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js +1 -1
- package/dist/production/src/graphql/resolvers/query/EventsQueryResolver.js.map +1 -1
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs +1 -4
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.cjs.map +1 -1
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js +1 -4
- package/dist/production/src/graphql/resolvers/query/VariablesQueryResolver.js.map +1 -1
- package/dist/production/src/graphql/schema/actions.graphql.cjs +20 -8
- package/dist/production/src/graphql/schema/actions.graphql.cjs.map +1 -1
- package/dist/production/src/graphql/schema/actions.graphql.js +20 -8
- package/dist/production/src/graphql/schema/actions.graphql.js.map +1 -1
- package/dist/production/src/migrations/index.cjs.map +1 -1
- package/dist/production/src/migrations/index.js.map +1 -1
- package/dist/production/src/model/EventByIdQuery.cjs.map +1 -1
- package/dist/production/src/model/EventByIdQuery.js.map +1 -1
- package/dist/production/src/model/EventsInProcessingQuery.cjs.map +1 -1
- package/dist/production/src/model/EventsInProcessingQuery.js.map +1 -1
- package/dist/production/src/model/EventsToProcessQuery.cjs.map +1 -1
- package/dist/production/src/model/EventsToProcessQuery.js.map +1 -1
- package/dist/production/src/model/FailedEventsQuery.cjs.map +1 -1
- package/dist/production/src/model/FailedEventsQuery.js.map +1 -1
- package/dist/production/src/model/VariablesManager.cjs +54 -5
- package/dist/production/src/model/VariablesManager.cjs.map +1 -1
- package/dist/production/src/model/VariablesManager.js +54 -5
- package/dist/production/src/model/VariablesManager.js.map +1 -1
- package/dist/production/src/triggers/TriggerHandler.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerHandler.js.map +1 -1
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerIndirectChangesFetcher.js.map +1 -1
- package/dist/production/src/triggers/TriggerListenersBuilder.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerListenersBuilder.js.map +1 -1
- package/dist/production/src/triggers/TriggerListenersFactory.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerListenersFactory.js.map +1 -1
- package/dist/production/src/triggers/TriggerListenersStore.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerListenersStore.js.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadBuilder.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadBuilder.js.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadManager.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadManager.js.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadPersister.cjs +3 -1
- package/dist/production/src/triggers/TriggerPayloadPersister.cjs.map +1 -1
- package/dist/production/src/triggers/TriggerPayloadPersister.js +3 -1
- package/dist/production/src/triggers/TriggerPayloadPersister.js.map +1 -1
- package/dist/tests/cases/unit/actionsMetrics.test.d.ts +2 -0
- package/dist/tests/cases/unit/actionsMetrics.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/actionsWebsocketController.test.d.ts +2 -0
- package/dist/tests/cases/unit/actionsWebsocketController.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/dispatchTracing.test.d.ts +2 -0
- package/dist/tests/cases/unit/dispatchTracing.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/eventsRepository.test.d.ts +2 -0
- package/dist/tests/cases/unit/eventsRepository.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/projectDispatcher.test.d.ts +2 -0
- package/dist/tests/cases/unit/projectDispatcher.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/variablesManager.test.d.ts +2 -0
- package/dist/tests/cases/unit/variablesManager.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/webhookTracing.test.d.ts +2 -0
- package/dist/tests/cases/unit/webhookTracing.test.d.ts.map +1 -0
- package/dist/tests/src/event.d.ts +4 -0
- package/dist/tests/src/event.d.ts.map +1 -0
- package/dist/tests/src/gql.d.ts.map +1 -1
- package/dist/tests/src/tracer.d.ts +7 -0
- package/dist/tests/src/tracer.d.ts.map +1 -0
- package/dist/tests/src/utils.d.ts +6 -0
- package/dist/tests/src/utils.d.ts.map +1 -0
- package/dist/tests/src/uuid.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ActionsExecutionContainerHookFactory.d.ts +4 -2
- package/dist/types/ActionsExecutionContainerHookFactory.d.ts.map +1 -1
- package/dist/types/ActionsMetrics.d.ts +59 -0
- package/dist/types/ActionsMetrics.d.ts.map +1 -0
- package/dist/types/ListenerStoreProvider.d.ts +1 -1
- package/dist/types/ListenerStoreProvider.d.ts.map +1 -1
- package/dist/types/authorization/ActionsPermissionsFactory.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +3 -3
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/dispatch/DispatchWorkerSupervisor.d.ts +1 -1
- package/dist/types/dispatch/DispatchWorkerSupervisor.d.ts.map +1 -1
- package/dist/types/dispatch/EventDispatcher.d.ts +18 -7
- package/dist/types/dispatch/EventDispatcher.d.ts.map +1 -1
- package/dist/types/dispatch/EventsRepository.d.ts +15 -3
- package/dist/types/dispatch/EventsRepository.d.ts.map +1 -1
- package/dist/types/dispatch/LazyDispatchWorker.d.ts +1 -1
- package/dist/types/dispatch/LazyDispatchWorker.d.ts.map +1 -1
- package/dist/types/dispatch/ProjectDispatcher.d.ts +11 -3
- package/dist/types/dispatch/ProjectDispatcher.d.ts.map +1 -1
- package/dist/types/dispatch/TargetHandlerResolver.d.ts +2 -2
- package/dist/types/dispatch/TargetHandlerResolver.d.ts.map +1 -1
- package/dist/types/dispatch/WebhookFetcher.d.ts.map +1 -1
- package/dist/types/dispatch/WebhookTargetHandler.d.ts +10 -3
- package/dist/types/dispatch/WebhookTargetHandler.d.ts.map +1 -1
- package/dist/types/dispatch/types.d.ts +2 -2
- package/dist/types/dispatch/types.d.ts.map +1 -1
- package/dist/types/graphql/http/ActionsApiMiddlewareFactory.d.ts +3 -3
- package/dist/types/graphql/http/ActionsApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/graphql/http/ActionsContextResolver.d.ts +1 -1
- package/dist/types/graphql/http/ActionsContextResolver.d.ts.map +1 -1
- package/dist/types/graphql/http/ActionsGraphQLHandlerFactory.d.ts +2 -2
- package/dist/types/graphql/http/ActionsGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts +7 -5
- package/dist/types/graphql/http/ActionsWebsocketControllerFactory.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/ResolversFactory.d.ts +4 -4
- package/dist/types/graphql/resolvers/ResolversFactory.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/index.d.ts +2 -2
- package/dist/types/graphql/resolvers/index.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/mutation/ProcessBatchMutationResolver.d.ts +3 -3
- package/dist/types/graphql/resolvers/mutation/ProcessBatchMutationResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/mutation/RetryEventMutationResolver.d.ts +3 -3
- package/dist/types/graphql/resolvers/mutation/RetryEventMutationResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts +3 -3
- package/dist/types/graphql/resolvers/mutation/SetVariablesMutationResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/mutation/StopEventMutationResolver.d.ts +3 -3
- package/dist/types/graphql/resolvers/mutation/StopEventMutationResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/mutation/index.d.ts +4 -4
- package/dist/types/graphql/resolvers/mutation/index.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/query/EventsQueryResolver.d.ts +2 -2
- package/dist/types/graphql/resolvers/query/EventsQueryResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts +4 -7
- package/dist/types/graphql/resolvers/query/VariablesQueryResolver.d.ts.map +1 -1
- package/dist/types/graphql/resolvers/query/index.d.ts +1 -1
- package/dist/types/graphql/resolvers/query/index.d.ts.map +1 -1
- package/dist/types/graphql/schema/actions.graphql.d.ts.map +1 -1
- package/dist/types/graphql/schema/index.d.ts +27 -17
- package/dist/types/graphql/schema/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/model/EventByIdQuery.d.ts +1 -1
- package/dist/types/model/EventByIdQuery.d.ts.map +1 -1
- package/dist/types/model/EventsInProcessingQuery.d.ts +2 -2
- package/dist/types/model/EventsInProcessingQuery.d.ts.map +1 -1
- package/dist/types/model/EventsToProcessQuery.d.ts +2 -2
- package/dist/types/model/EventsToProcessQuery.d.ts.map +1 -1
- package/dist/types/model/FailedEventsQuery.d.ts +2 -2
- package/dist/types/model/FailedEventsQuery.d.ts.map +1 -1
- package/dist/types/model/SetVariableCommand.d.ts.map +1 -1
- package/dist/types/model/VariablesManager.d.ts +16 -3
- package/dist/types/model/VariablesManager.d.ts.map +1 -1
- package/dist/types/model/VariablesQuery.d.ts.map +1 -1
- package/dist/types/triggers/TriggerHandler.d.ts +3 -3
- package/dist/types/triggers/TriggerHandler.d.ts.map +1 -1
- package/dist/types/triggers/TriggerIndirectChangesFetcher.d.ts +1 -1
- package/dist/types/triggers/TriggerIndirectChangesFetcher.d.ts.map +1 -1
- package/dist/types/triggers/TriggerListeners.d.ts +1 -1
- package/dist/types/triggers/TriggerListeners.d.ts.map +1 -1
- package/dist/types/triggers/TriggerListenersBuilder.d.ts +1 -1
- package/dist/types/triggers/TriggerListenersBuilder.d.ts.map +1 -1
- package/dist/types/triggers/TriggerListenersFactory.d.ts +1 -1
- package/dist/types/triggers/TriggerListenersFactory.d.ts.map +1 -1
- package/dist/types/triggers/TriggerListenersStore.d.ts +1 -1
- package/dist/types/triggers/TriggerListenersStore.d.ts.map +1 -1
- package/dist/types/triggers/TriggerPayloadBuilder.d.ts +1 -1
- package/dist/types/triggers/TriggerPayloadBuilder.d.ts.map +1 -1
- package/dist/types/triggers/TriggerPayloadManager.d.ts +4 -4
- package/dist/types/triggers/TriggerPayloadManager.d.ts.map +1 -1
- package/dist/types/triggers/TriggerPayloadPersister.d.ts +3 -1
- package/dist/types/triggers/TriggerPayloadPersister.d.ts.map +1 -1
- package/dist/types/triggers/index.d.ts +7 -7
- package/dist/types/triggers/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/map.d.ts.map +1 -1
- package/dist/types/utils/notifyChannel.d.ts.map +1 -1
- package/graphql.codegen.yml +1 -1
- package/package.json +19 -16
- package/src/ActionsExecutionContainerHookFactory.ts +10 -4
- package/src/ActionsMetrics.ts +135 -0
- package/src/ListenerStoreProvider.ts +1 -1
- package/src/authorization/ActionsPermissionsFactory.ts +1 -1
- package/src/authorization/index.ts +3 -3
- package/src/dispatch/DispatchWorkerSupervisor.ts +2 -2
- package/src/dispatch/EventDispatcher.ts +77 -28
- package/src/dispatch/EventsRepository.ts +72 -29
- package/src/dispatch/LazyDispatchWorker.ts +1 -1
- package/src/dispatch/ProjectDispatcher.ts +81 -21
- package/src/dispatch/TargetHandlerResolver.ts +3 -3
- package/src/dispatch/WebhookTargetHandler.ts +119 -5
- package/src/dispatch/types.ts +2 -2
- package/src/graphql/http/ActionsApiMiddlewareFactory.ts +4 -4
- package/src/graphql/http/ActionsContextResolver.ts +1 -1
- package/src/graphql/http/ActionsGraphQLHandlerFactory.ts +3 -2
- package/src/graphql/http/ActionsWebsocketControllerFactory.ts +73 -30
- package/src/graphql/resolvers/ResolversFactory.ts +11 -6
- package/src/graphql/resolvers/index.ts +2 -2
- package/src/graphql/resolvers/mutation/ProcessBatchMutationResolver.ts +4 -4
- package/src/graphql/resolvers/mutation/RetryEventMutationResolver.ts +5 -5
- package/src/graphql/resolvers/mutation/SetVariablesMutationResolver.ts +5 -5
- package/src/graphql/resolvers/mutation/StopEventMutationResolver.ts +4 -4
- package/src/graphql/resolvers/mutation/index.ts +4 -4
- package/src/graphql/resolvers/query/EventsQueryResolver.ts +9 -9
- package/src/graphql/resolvers/query/VariablesQueryResolver.ts +5 -8
- package/src/graphql/resolvers/query/index.ts +1 -1
- package/src/graphql/schema/actions.graphql.ts +20 -8
- package/src/graphql/schema/index.ts +30 -17
- package/src/index.ts +61 -32
- package/src/migrations/index.ts +3 -3
- package/src/model/EventByIdQuery.ts +1 -1
- package/src/model/EventsInProcessingQuery.ts +2 -2
- package/src/model/EventsToProcessQuery.ts +3 -3
- package/src/model/FailedEventsQuery.ts +2 -2
- package/src/model/VariablesManager.ts +68 -8
- package/src/triggers/TriggerHandler.ts +3 -3
- package/src/triggers/TriggerIndirectChangesFetcher.ts +1 -1
- package/src/triggers/TriggerListeners.ts +1 -1
- package/src/triggers/TriggerListenersBuilder.ts +4 -4
- package/src/triggers/TriggerListenersFactory.ts +2 -2
- package/src/triggers/TriggerListenersStore.ts +1 -1
- package/src/triggers/TriggerPayloadBuilder.ts +3 -3
- package/src/triggers/TriggerPayloadManager.ts +4 -4
- package/src/triggers/TriggerPayloadPersister.ts +8 -2
- package/src/triggers/index.ts +7 -7
- package/src/tsconfig.json +1 -0
- package/tests/cases/unit/actionsMetrics.test.ts +76 -0
- package/tests/cases/unit/actionsWebsocketController.test.ts +270 -0
- package/tests/cases/unit/dispatchTracing.test.ts +204 -0
- package/tests/cases/unit/eventsRepository.test.ts +158 -0
- package/tests/cases/unit/generator.test.ts +1 -1
- package/tests/cases/unit/lazyDispatchWorker.test.ts +2 -2
- package/tests/cases/unit/projectDispatcher.test.ts +114 -0
- package/tests/cases/unit/variablesManager.test.ts +154 -0
- package/tests/cases/unit/webhookHandler.test.ts +94 -35
- package/tests/cases/unit/webhookTracing.test.ts +163 -0
- package/tests/src/event.ts +27 -0
- package/tests/src/tracer.ts +11 -0
- package/tests/src/utils.ts +5 -0
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import { DatabaseContext } from '@contember/engine-system-api'
|
|
2
|
-
import { EventDispatcher } from './EventDispatcher'
|
|
2
|
+
import { EventDispatcher } from './EventDispatcher.js'
|
|
3
3
|
import { ContentSchemaResolver } from '@contember/engine-http'
|
|
4
4
|
import { Runnable, RunnableArgs, Running } from '@contember/engine-common'
|
|
5
5
|
import { Listener } from '@contember/database'
|
|
6
|
-
import { NOTIFY_CHANNEL_NAME } from '../utils/notifyChannel'
|
|
6
|
+
import { NOTIFY_CHANNEL_NAME } from '../utils/notifyChannel.js'
|
|
7
|
+
import { ActionsMetrics, ProjectActionsMetrics } from '../ActionsMetrics.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Upper bound on how long the loop parks while idle. Even when the queue is empty (and we'd
|
|
11
|
+
* otherwise wait indefinitely on a `pg_notify`), we re-check at least this often, so a lost
|
|
12
|
+
* notification self-heals and the heartbeat keeps refreshing while the worker is genuinely idle.
|
|
13
|
+
*/
|
|
14
|
+
const MAX_IDLE_SLEEP_MS = 30_000
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* How long `end()` waits for an in-flight batch. A webhook may take its full target timeout, which would
|
|
18
|
+
* outlive a typical shutdown grace period. Events of an abandoned batch stay in processing and are
|
|
19
|
+
* delivered again once their ACK timeout expires.
|
|
20
|
+
*/
|
|
21
|
+
const END_TIMEOUT_MS = 10_000
|
|
22
|
+
|
|
23
|
+
export interface ProjectDispatcherOptions {
|
|
24
|
+
readonly endTimeoutMs?: number
|
|
25
|
+
}
|
|
7
26
|
|
|
8
27
|
export class ProjectDispatcherFactory {
|
|
9
28
|
constructor(
|
|
10
29
|
private readonly dispatcher: EventDispatcher,
|
|
30
|
+
private readonly metrics: ActionsMetrics,
|
|
11
31
|
) {
|
|
12
32
|
}
|
|
13
33
|
|
|
14
34
|
public create(
|
|
15
35
|
{ db, contentSchemaResolver, projectSlug }: { db: DatabaseContext; contentSchemaResolver: ContentSchemaResolver; projectSlug: string },
|
|
16
36
|
): ProjectDispatcher {
|
|
17
|
-
return new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug)
|
|
37
|
+
return new ProjectDispatcher(this.dispatcher, db, contentSchemaResolver, projectSlug, this.metrics.forProject(projectSlug))
|
|
18
38
|
}
|
|
19
39
|
}
|
|
20
40
|
|
|
@@ -24,11 +44,31 @@ export class ProjectDispatcher implements Runnable {
|
|
|
24
44
|
private readonly db: DatabaseContext,
|
|
25
45
|
private readonly contentSchemaResolver: ContentSchemaResolver,
|
|
26
46
|
private readonly projectSlug: string,
|
|
47
|
+
private readonly metrics: ProjectActionsMetrics,
|
|
48
|
+
private readonly options: ProjectDispatcherOptions = {},
|
|
27
49
|
) {
|
|
28
50
|
}
|
|
29
51
|
|
|
52
|
+
private async waitForDispatchToFinish(dispatchFinished: Promise<void>): Promise<boolean> {
|
|
53
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
54
|
+
try {
|
|
55
|
+
return await Promise.race([
|
|
56
|
+
dispatchFinished.then(() => true),
|
|
57
|
+
new Promise<boolean>(resolve => {
|
|
58
|
+
timer = setTimeout(() => resolve(false), this.options.endTimeoutMs ?? END_TIMEOUT_MS)
|
|
59
|
+
}),
|
|
60
|
+
])
|
|
61
|
+
} finally {
|
|
62
|
+
clearTimeout(timer)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
30
66
|
public async run({ logger, onError, onClose }: RunnableArgs): Promise<Running> {
|
|
31
67
|
return await new Promise<Running>(async (resolve, reject) => {
|
|
68
|
+
let resolveDispatchFinished = () => {}
|
|
69
|
+
const dispatchFinished = new Promise<void>(resolve => {
|
|
70
|
+
resolveDispatchFinished = resolve
|
|
71
|
+
})
|
|
32
72
|
let resolvePending = () => {}
|
|
33
73
|
let rejectPending = (e: any) => {}
|
|
34
74
|
|
|
@@ -44,6 +84,7 @@ export class ProjectDispatcher implements Runnable {
|
|
|
44
84
|
let succeedTotal = 0
|
|
45
85
|
let failedTotal = 0
|
|
46
86
|
let aborted = false
|
|
87
|
+
let endPromise: Promise<void> | undefined
|
|
47
88
|
|
|
48
89
|
try {
|
|
49
90
|
await this.db.scope(async db => {
|
|
@@ -55,40 +96,55 @@ export class ProjectDispatcher implements Runnable {
|
|
|
55
96
|
.run({ onError: rejectPendingRef, onClose: resolvePendingRef })
|
|
56
97
|
|
|
57
98
|
resolve({
|
|
58
|
-
end:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
99
|
+
end: () => {
|
|
100
|
+
endPromise ??= (async () => {
|
|
101
|
+
aborted = true
|
|
102
|
+
resolvePendingRef()
|
|
103
|
+
const finished = await this.waitForDispatchToFinish(dispatchFinished)
|
|
104
|
+
if (!finished) {
|
|
105
|
+
logger.warn('Worker did not finish its batch in time, events still in processing will be delivered again')
|
|
106
|
+
}
|
|
107
|
+
this.metrics.dispose()
|
|
108
|
+
logger.info('Worker terminated', {
|
|
109
|
+
succeed: succeedTotal,
|
|
110
|
+
failed: failedTotal,
|
|
111
|
+
})
|
|
112
|
+
})()
|
|
113
|
+
return endPromise
|
|
65
114
|
},
|
|
66
115
|
})
|
|
67
116
|
|
|
68
117
|
try {
|
|
69
118
|
while (!aborted) {
|
|
70
|
-
|
|
119
|
+
this.metrics.heartbeat()
|
|
120
|
+
const { succeeded, retried, failedAfterAttempt, failedUnknownTarget, backoffMs } = await this.dispatcher.processBatch({
|
|
71
121
|
db,
|
|
72
122
|
contentSchemaResolver: this.contentSchemaResolver,
|
|
73
123
|
logger,
|
|
124
|
+
project: { slug: this.projectSlug },
|
|
74
125
|
})
|
|
75
|
-
|
|
76
|
-
|
|
126
|
+
const terminalFailed = failedAfterAttempt + failedUnknownTarget
|
|
127
|
+
this.metrics.succeeded(succeeded)
|
|
128
|
+
this.metrics.deliveryAttemptFailed(retried + failedAfterAttempt)
|
|
129
|
+
this.metrics.failed(terminalFailed)
|
|
130
|
+
succeedTotal += succeeded
|
|
131
|
+
failedTotal += terminalFailed
|
|
77
132
|
|
|
78
133
|
// listener error occurred during batch processing, rethrow
|
|
79
134
|
if (pendingError) {
|
|
80
135
|
throw pendingError
|
|
81
136
|
}
|
|
137
|
+
if (aborted) {
|
|
138
|
+
break
|
|
139
|
+
}
|
|
82
140
|
|
|
83
|
-
// queue is empty, wait
|
|
141
|
+
// queue is empty (or next retry is in the future), wait — but never longer than
|
|
142
|
+
// MAX_IDLE_SLEEP_MS, so a lost notification self-heals and the heartbeat stays fresh.
|
|
84
143
|
if (backoffMs !== 0) {
|
|
144
|
+
const waitMs = Math.min(backoffMs ?? MAX_IDLE_SLEEP_MS, MAX_IDLE_SLEEP_MS)
|
|
85
145
|
await new Promise<void>((resolve, reject) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (backoffMs !== undefined) {
|
|
89
|
-
const timeoutHandle = setTimeout(resolve, backoffMs)
|
|
90
|
-
cleanup = () => clearTimeout(timeoutHandle)
|
|
91
|
-
}
|
|
146
|
+
const timeoutHandle = setTimeout(resolve, waitMs)
|
|
147
|
+
const cleanup = () => clearTimeout(timeoutHandle)
|
|
92
148
|
resolvePending = () => {
|
|
93
149
|
resolve()
|
|
94
150
|
cleanup()
|
|
@@ -102,12 +158,16 @@ export class ProjectDispatcher implements Runnable {
|
|
|
102
158
|
}
|
|
103
159
|
onClose?.()
|
|
104
160
|
} catch (e) {
|
|
105
|
-
|
|
161
|
+
this.metrics.crashed()
|
|
106
162
|
onError(e)
|
|
163
|
+
} finally {
|
|
164
|
+
await listener.end()
|
|
107
165
|
}
|
|
108
166
|
})
|
|
109
167
|
} catch (e) {
|
|
110
168
|
reject(e)
|
|
169
|
+
} finally {
|
|
170
|
+
resolveDispatchFinished()
|
|
111
171
|
}
|
|
112
172
|
})
|
|
113
173
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Actions } from '@contember/schema'
|
|
2
|
-
import { WebhookTargetHandler } from './WebhookTargetHandler'
|
|
3
|
-
import { ImplementationException } from '../ImplementationException'
|
|
4
|
-
import { InvokeHandler } from './types'
|
|
2
|
+
import { WebhookTargetHandler } from './WebhookTargetHandler.js'
|
|
3
|
+
import { ImplementationException } from '../ImplementationException.js'
|
|
4
|
+
import { InvokeHandler } from './types.js'
|
|
5
5
|
|
|
6
6
|
export class TargetHandlerResolver {
|
|
7
7
|
constructor(
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Actions, ActionsPayload } from '@contember/schema'
|
|
2
|
-
import { EventRow, HandledEvent, InvokeHandler, InvokeHandlerArgs } from './types'
|
|
3
|
-
import { VariablesMap } from '../model/VariablesManager'
|
|
2
|
+
import { EventRow, HandledEvent, InvokeHandler, InvokeHandlerArgs } from './types.js'
|
|
3
|
+
import { VariablesMap } from '../model/VariablesManager.js'
|
|
4
4
|
import * as Typesafe from '@contember/typesafe'
|
|
5
|
-
import { FetcherResponse, WebhookFetcher } from './WebhookFetcher'
|
|
5
|
+
import { FetcherResponse, WebhookFetcher } from './WebhookFetcher.js'
|
|
6
|
+
import { Logger } from '@contember/logger'
|
|
7
|
+
import { formatTraceparent, INVALID_TRACE_ID, Tracer } from '@contember/telemetry'
|
|
6
8
|
|
|
7
9
|
const DEFAULT_TIMEOUT_MS = 30_000 // 30 seconds
|
|
8
10
|
|
|
@@ -21,9 +23,44 @@ const ResponseType = Typesafe.noExtraProps(Typesafe.object({
|
|
|
21
23
|
|
|
22
24
|
type EventResponseFactory = (eventRow: EventRow) => { ok: boolean; code?: number; response?: string; errorMessage?: string; durationMs?: number }
|
|
23
25
|
|
|
26
|
+
class WebhookRequestError extends Error {
|
|
27
|
+
public readonly code?: string | number
|
|
28
|
+
|
|
29
|
+
constructor(error: unknown) {
|
|
30
|
+
super('Webhook request failed')
|
|
31
|
+
try {
|
|
32
|
+
if (error instanceof Error) {
|
|
33
|
+
this.name = error.name
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
const seen = new Set<object>()
|
|
38
|
+
let current = error
|
|
39
|
+
while (typeof current === 'object' && current !== null && !seen.has(current)) {
|
|
40
|
+
seen.add(current)
|
|
41
|
+
try {
|
|
42
|
+
const code = 'code' in current ? current.code : undefined
|
|
43
|
+
if (typeof code === 'string' || typeof code === 'number') {
|
|
44
|
+
this.code = code
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
current = 'cause' in current ? current.cause : undefined
|
|
48
|
+
} catch {
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type WebhookTargetHandlerOptions = {
|
|
56
|
+
propagateToWebhooks: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
24
59
|
export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget> {
|
|
25
60
|
constructor(
|
|
26
61
|
private readonly fetcher: WebhookFetcher,
|
|
62
|
+
private readonly tracer: Tracer,
|
|
63
|
+
private readonly options: WebhookTargetHandlerOptions,
|
|
27
64
|
) {
|
|
28
65
|
}
|
|
29
66
|
|
|
@@ -35,11 +72,36 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
35
72
|
|
|
36
73
|
let eventResponseFactory: EventResponseFactory
|
|
37
74
|
try {
|
|
38
|
-
|
|
75
|
+
// The target is identified by name only: its URL and headers may carry credentials.
|
|
76
|
+
const span = this.tracer.startSpan('webhook', {
|
|
77
|
+
kind: 'client',
|
|
78
|
+
attributes: {
|
|
79
|
+
'contember.actions.target': target.name,
|
|
80
|
+
'contember.actions.events': events.length,
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
const response = await this.tracer.withSpan(span, async () => {
|
|
84
|
+
try {
|
|
85
|
+
const response = await this.fetch(timeoutMs ?? DEFAULT_TIMEOUT_MS, target, variables, events)
|
|
86
|
+
span.setAttribute('http.response.status_code', response.status)
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
span.setStatus('error')
|
|
89
|
+
}
|
|
90
|
+
return response
|
|
91
|
+
} catch (error) {
|
|
92
|
+
span.recordException(new WebhookRequestError(error))
|
|
93
|
+
span.setStatus('error', 'Webhook request failed')
|
|
94
|
+
throw error
|
|
95
|
+
} finally {
|
|
96
|
+
span.end()
|
|
97
|
+
}
|
|
98
|
+
})
|
|
39
99
|
|
|
40
100
|
eventResponseFactory = this.createResponseFactory({
|
|
41
101
|
response: response,
|
|
42
102
|
events,
|
|
103
|
+
target,
|
|
104
|
+
logger,
|
|
43
105
|
})
|
|
44
106
|
} catch (e) {
|
|
45
107
|
logger.warn(e)
|
|
@@ -58,11 +120,20 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
58
120
|
return events.map(it => ({ target, row: it, result: { durationMs, ...eventResponseFactory(it) } }))
|
|
59
121
|
}
|
|
60
122
|
|
|
61
|
-
private createResponseFactory({ response, events }: {
|
|
123
|
+
private createResponseFactory({ response, events, target, logger }: {
|
|
62
124
|
response: FetcherResponse
|
|
63
125
|
events: EventRow[]
|
|
126
|
+
target: Actions.WebhookTarget
|
|
127
|
+
logger: Logger
|
|
64
128
|
}): EventResponseFactory {
|
|
65
129
|
if (!response.ok) {
|
|
130
|
+
// The target is identified by name only: its URL and headers may carry credentials.
|
|
131
|
+
logger.warn('Webhook target responded with an error status', {
|
|
132
|
+
target: target.name,
|
|
133
|
+
status: response.status,
|
|
134
|
+
statusText: response.statusText,
|
|
135
|
+
events: events.map(it => it.id),
|
|
136
|
+
})
|
|
66
137
|
return () => ({
|
|
67
138
|
ok: false,
|
|
68
139
|
code: response.status,
|
|
@@ -95,6 +166,13 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
95
166
|
const missingEvents = Object.keys(failedEvents).filter(it => !eventsInBatch.has(it))
|
|
96
167
|
|
|
97
168
|
if (missingEvents.length) {
|
|
169
|
+
// Only the count of unknown ids: they are strings the target chose, not ours.
|
|
170
|
+
logger.warn('Webhook target reported failures for event ids outside the batch', {
|
|
171
|
+
target: target.name,
|
|
172
|
+
status: response.status,
|
|
173
|
+
unknownEventIds: missingEvents.length,
|
|
174
|
+
events: events.map(it => it.id),
|
|
175
|
+
})
|
|
98
176
|
return () => ({
|
|
99
177
|
ok: false,
|
|
100
178
|
code: response.status,
|
|
@@ -103,6 +181,16 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
103
181
|
})
|
|
104
182
|
}
|
|
105
183
|
|
|
184
|
+
const failedIds = events.filter(it => failedEvents[it.id]).map(it => it.id)
|
|
185
|
+
if (failedIds.length) {
|
|
186
|
+
// Per-event errors come from the target's payload and stay in the event log, not here.
|
|
187
|
+
logger.warn('Webhook target reported failed events', {
|
|
188
|
+
target: target.name,
|
|
189
|
+
status: response.status,
|
|
190
|
+
events: failedIds,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
106
194
|
return it => {
|
|
107
195
|
if (!failedEvents[it.id]) {
|
|
108
196
|
return { ok: true, code: response.status }
|
|
@@ -114,6 +202,12 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
114
202
|
}
|
|
115
203
|
}
|
|
116
204
|
} catch (e: any) {
|
|
205
|
+
// The parser message quotes the offending payload, so it stays in the event log only.
|
|
206
|
+
logger.warn('Webhook target returned a malformed response', {
|
|
207
|
+
target: target.name,
|
|
208
|
+
status: response.status,
|
|
209
|
+
events: events.map(it => it.id),
|
|
210
|
+
})
|
|
117
211
|
return () => ({
|
|
118
212
|
ok: false,
|
|
119
213
|
code: response.status,
|
|
@@ -155,6 +249,7 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
155
249
|
method: 'POST',
|
|
156
250
|
headers: {
|
|
157
251
|
['User-Agent']: 'Contember Actions',
|
|
252
|
+
...this.createTraceHeaders(resolvedHeaders),
|
|
158
253
|
...resolvedHeaders,
|
|
159
254
|
['Content-type']: 'application/json',
|
|
160
255
|
},
|
|
@@ -163,6 +258,25 @@ export class WebhookTargetHandler implements InvokeHandler<Actions.WebhookTarget
|
|
|
163
258
|
})
|
|
164
259
|
}
|
|
165
260
|
|
|
261
|
+
private createTraceHeaders(resolvedHeaders: Record<string, string>): Record<string, string> {
|
|
262
|
+
if (this.options.propagateToWebhooks === false) {
|
|
263
|
+
return {}
|
|
264
|
+
}
|
|
265
|
+
const activeContext = this.tracer.activeSpanContext()
|
|
266
|
+
if (activeContext === undefined || activeContext.traceId === INVALID_TRACE_ID) {
|
|
267
|
+
return {}
|
|
268
|
+
}
|
|
269
|
+
// A target-configured header wins, in whatever case it was written.
|
|
270
|
+
if (Object.keys(resolvedHeaders).some(it => it.toLowerCase() === 'traceparent')) {
|
|
271
|
+
return {}
|
|
272
|
+
}
|
|
273
|
+
const traceState = activeContext.traceState
|
|
274
|
+
return {
|
|
275
|
+
traceparent: formatTraceparent(activeContext),
|
|
276
|
+
...(traceState !== undefined ? { tracestate: traceState } : {}),
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
166
280
|
private formatBody(events: EventRow[], target: Actions.WebhookTarget): string {
|
|
167
281
|
const body = target.body ?? {}
|
|
168
282
|
const path = target.payloadPath ?? []
|
package/src/dispatch/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from '@contember/logger'
|
|
2
2
|
import { Actions } from '@contember/schema'
|
|
3
|
-
import { EventRow } from '../model/types'
|
|
4
|
-
import { VariablesMap } from '../model/VariablesManager'
|
|
3
|
+
import { EventRow } from '../model/types.js'
|
|
4
|
+
import { VariablesMap } from '../model/VariablesManager.js'
|
|
5
5
|
|
|
6
6
|
export type { EventRow }
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { HttpController } from '@contember/engine-http'
|
|
2
|
-
import { ActionsGraphQLHandler } from './ActionsGraphQLHandlerFactory'
|
|
3
|
-
import { ActionsContext } from '../resolvers/ActionsContext'
|
|
4
|
-
import { ActionsContextResolver } from './ActionsContextResolver'
|
|
2
|
+
import { ActionsGraphQLHandler } from './ActionsGraphQLHandlerFactory.js'
|
|
3
|
+
import { ActionsContext } from '../resolvers/ActionsContext.js'
|
|
4
|
+
import { ActionsContextResolver } from './ActionsContextResolver.js'
|
|
5
5
|
import { AuthorizationScope, Authorizator } from '@contember/authorization'
|
|
6
|
-
import { Identity } from '../../authorization'
|
|
6
|
+
import { Identity } from '../../authorization/index.js'
|
|
7
7
|
import { ForbiddenError } from '@contember/graphql-utils'
|
|
8
8
|
|
|
9
9
|
export class ActionsApiMiddlewareFactory {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApplicationContext, HttpErrorResponse, ProjectConfig, ProjectContainer, ProjectContextResolver } from '@contember/engine-http'
|
|
2
|
-
import { Identity } from '../../authorization'
|
|
2
|
+
import { Identity } from '../../authorization/index.js'
|
|
3
3
|
|
|
4
4
|
export interface ActionsContext {
|
|
5
5
|
projectContainer: ProjectContainer
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { makeExecutableSchema } from '@graphql-tools/schema'
|
|
2
2
|
import { createGraphQLQueryHandler, GraphQLQueryHandler } from '@contember/engine-http'
|
|
3
|
-
import { ResolversFactory } from '../resolvers/ResolversFactory'
|
|
3
|
+
import { ResolversFactory } from '../resolvers/ResolversFactory.js'
|
|
4
|
+
// biome-ignore lint/correctness/useImportExtensions: .graphql files are resolved by the bundler loader, not as JS modules
|
|
4
5
|
import { schema as graphqlDocument } from '../schema/actions.graphql'
|
|
5
|
-
import { ActionsContext } from '../resolvers/ActionsContext'
|
|
6
|
+
import { ActionsContext } from '../resolvers/ActionsContext.js'
|
|
6
7
|
|
|
7
8
|
export type ActionsGraphQLHandler = GraphQLQueryHandler<ActionsContext>
|
|
8
9
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { HttpErrorResponse, WebSocketController } from '@contember/engine-http'
|
|
2
|
-
import { ActionsContextResolver } from './ActionsContextResolver'
|
|
3
|
-
import { DispatchWorkerSupervisorFactory } from '../../dispatch/DispatchWorkerSupervisor'
|
|
1
|
+
import { HttpErrorResponse, ProjectGroupContainer, WebSocketController } from '@contember/engine-http'
|
|
4
2
|
import * as Typesafe from '@contember/typesafe'
|
|
5
3
|
import { TenantRole } from '@contember/engine-tenant-api'
|
|
6
|
-
import { Running } from '@contember/engine-common'
|
|
4
|
+
import { Runnable, Running } from '@contember/engine-common'
|
|
7
5
|
|
|
8
6
|
const IncomingMessage = Typesafe.discriminatedUnion(
|
|
9
7
|
'type',
|
|
@@ -41,11 +39,14 @@ const OutgoingMessage = Typesafe.discriminatedUnion(
|
|
|
41
39
|
|
|
42
40
|
type OutgoingMessage = ReturnType<typeof OutgoingMessage>
|
|
43
41
|
|
|
42
|
+
type DispatchWorkerFactory = {
|
|
43
|
+
create(projectGroup: ProjectGroupContainer): Runnable
|
|
44
|
+
}
|
|
45
|
+
|
|
44
46
|
export class ActionsWebsocketControllerFactory {
|
|
45
47
|
constructor(
|
|
46
48
|
private readonly debug: boolean,
|
|
47
|
-
private readonly
|
|
48
|
-
private readonly dispatchWorkerSupervisorFactory: DispatchWorkerSupervisorFactory,
|
|
49
|
+
private readonly dispatchWorkerSupervisorFactory: DispatchWorkerFactory,
|
|
49
50
|
) {
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -67,24 +68,44 @@ export class ActionsWebsocketControllerFactory {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
let workers: { id: string; running: Promise<Running> }[] = []
|
|
71
|
+
let stopAllPromise: Promise<void> | undefined
|
|
72
|
+
let connectionClosing = false
|
|
70
73
|
const abortListener = async () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
connectionClosing = true
|
|
75
|
+
try {
|
|
76
|
+
send({ type: 'message', message: 'shutting down' })
|
|
77
|
+
await stopAll()
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error(error, { message: 'Websocket worker cleanup failed' })
|
|
80
|
+
} finally {
|
|
81
|
+
try {
|
|
82
|
+
send({ type: 'message', message: 'closing connection' })
|
|
83
|
+
} finally {
|
|
84
|
+
ws.close(1012) // Service Restart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
75
87
|
}
|
|
76
88
|
ctx.abortSignal.addEventListener('abort', abortListener)
|
|
77
89
|
|
|
78
|
-
const stopAll =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
const stopAll = (): Promise<void> => {
|
|
91
|
+
stopAllPromise ??= (async () => {
|
|
92
|
+
// a worker stays tracked until its own end() resolves, so a failed cleanup is not forgotten
|
|
93
|
+
const results = await Promise.allSettled(workers.map(async it => {
|
|
94
|
+
await (await it.running).end()
|
|
95
|
+
workers = workers.filter(worker => worker !== it)
|
|
96
|
+
send({
|
|
97
|
+
type: 'workedStopped',
|
|
98
|
+
workerId: it.id,
|
|
99
|
+
})
|
|
100
|
+
}))
|
|
101
|
+
const errors = results.flatMap(it => it.status === 'rejected' ? [it.reason] : [])
|
|
102
|
+
if (errors.length > 0) {
|
|
103
|
+
throw new AggregateError(errors, 'Worker cleanup failed')
|
|
104
|
+
}
|
|
105
|
+
})().finally(() => {
|
|
106
|
+
stopAllPromise = undefined
|
|
85
107
|
})
|
|
86
|
-
|
|
87
|
-
await Promise.all(currentWorkers)
|
|
108
|
+
return stopAllPromise
|
|
88
109
|
}
|
|
89
110
|
send({ type: 'ready' })
|
|
90
111
|
|
|
@@ -110,27 +131,41 @@ export class ActionsWebsocketControllerFactory {
|
|
|
110
131
|
|
|
111
132
|
switch (data.type) {
|
|
112
133
|
case 'startWorker':
|
|
134
|
+
if (connectionClosing || stopAllPromise !== undefined) {
|
|
135
|
+
send({ type: 'error', message: 'Workers are stopping' })
|
|
136
|
+
break
|
|
137
|
+
}
|
|
113
138
|
const workerId = Math.random().toString().substring(2)
|
|
114
139
|
const dispatchSupervisor = this.dispatchWorkerSupervisorFactory.create(projectGroup)
|
|
115
|
-
|
|
116
|
-
|
|
140
|
+
const running = Promise.resolve().then(() =>
|
|
141
|
+
dispatchSupervisor.run({
|
|
117
142
|
logger,
|
|
118
143
|
onError: () => {
|
|
119
144
|
send({ type: 'workerCrashed', workerId })
|
|
120
145
|
},
|
|
121
146
|
})
|
|
122
|
-
|
|
147
|
+
)
|
|
148
|
+
const worker = { id: workerId, running }
|
|
149
|
+
workers.push(worker)
|
|
150
|
+
try {
|
|
123
151
|
await running
|
|
124
|
-
send({ type: 'workerStarted', workerId })
|
|
125
152
|
} catch (e) {
|
|
153
|
+
workers = workers.filter(it => it !== worker)
|
|
126
154
|
logger.error(e, { message: 'Worker failed to start' })
|
|
127
155
|
send({ type: 'workerFailedToStart', workerId })
|
|
156
|
+
break
|
|
128
157
|
}
|
|
158
|
+
send({ type: 'workerStarted', workerId })
|
|
129
159
|
break
|
|
130
160
|
case 'stopAllWorkers':
|
|
131
161
|
send({ type: 'message', message: 'stopping' })
|
|
132
|
-
|
|
133
|
-
|
|
162
|
+
try {
|
|
163
|
+
await stopAll()
|
|
164
|
+
send({ type: 'message', message: 'all stopped' })
|
|
165
|
+
} catch (error) {
|
|
166
|
+
logger.error(error, { message: 'Websocket worker cleanup failed' })
|
|
167
|
+
send({ type: 'error', message: 'Worker cleanup failed' })
|
|
168
|
+
}
|
|
134
169
|
break
|
|
135
170
|
}
|
|
136
171
|
})
|
|
@@ -139,11 +174,19 @@ export class ActionsWebsocketControllerFactory {
|
|
|
139
174
|
ws.ping()
|
|
140
175
|
}, 5000)
|
|
141
176
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
177
|
+
ctx.waitUntil(
|
|
178
|
+
new Promise<void>(resolve => {
|
|
179
|
+
ws.addEventListener('close', () => {
|
|
180
|
+
connectionClosing = true
|
|
181
|
+
ctx.abortSignal.removeEventListener('abort', abortListener)
|
|
182
|
+
clearInterval(pingHandle)
|
|
183
|
+
void stopAll().then(resolve, error => {
|
|
184
|
+
logger.error(error, { message: 'Websocket worker cleanup failed' })
|
|
185
|
+
resolve()
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}),
|
|
189
|
+
)
|
|
147
190
|
}
|
|
148
191
|
}
|
|
149
192
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { DateTimeType, JSONType, UuidType } from '@contember/graphql-utils'
|
|
2
|
-
import { Resolvers } from '../schema'
|
|
3
|
-
import { EventsQueryResolver } from './query'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { Resolvers } from '../schema/index.js'
|
|
3
|
+
import { EventsQueryResolver } from './query/index.js'
|
|
4
|
+
import {
|
|
5
|
+
ProcessBatchMutationResolver,
|
|
6
|
+
RetryEventMutationResolver,
|
|
7
|
+
SetVariablesMutationResolver,
|
|
8
|
+
StopEventMutationResolver,
|
|
9
|
+
} from './mutation/index.js'
|
|
10
|
+
import { ActionsContext } from './ActionsContext.js'
|
|
11
|
+
import { VariablesQueryResolver } from './query/VariablesQueryResolver.js'
|
|
7
12
|
|
|
8
13
|
export class ResolversFactory {
|
|
9
14
|
constructor(
|
|
@@ -22,7 +27,7 @@ export class ResolversFactory {
|
|
|
22
27
|
} = {
|
|
23
28
|
Json: JSONType,
|
|
24
29
|
DateTime: DateTimeType,
|
|
25
|
-
|
|
30
|
+
UUID: UuidType,
|
|
26
31
|
Mutation: {
|
|
27
32
|
processBatch: this.processBatchMutationResolver.processBatch.bind(this.processBatchMutationResolver),
|
|
28
33
|
setVariables: this.setVariablesMutationResolver.setVariables.bind(this.setVariablesMutationResolver),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './mutation'
|
|
2
|
-
export * from './query'
|
|
1
|
+
export * from './mutation/index.js'
|
|
2
|
+
export * from './query/index.js'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MutationResolvers } from '../../schema'
|
|
2
|
-
import { ActionsContext } from '../ActionsContext'
|
|
3
|
-
import { EventDispatcher } from '../../../dispatch/EventDispatcher'
|
|
4
|
-
import { ActionsAuthorizationActions } from '../../../authorization'
|
|
1
|
+
import { MutationResolvers } from '../../schema/index.js'
|
|
2
|
+
import { ActionsContext } from '../ActionsContext.js'
|
|
3
|
+
import { EventDispatcher } from '../../../dispatch/EventDispatcher.js'
|
|
4
|
+
import { ActionsAuthorizationActions } from '../../../authorization/index.js'
|
|
5
5
|
|
|
6
6
|
export class ProcessBatchMutationResolver implements MutationResolvers<ActionsContext> {
|
|
7
7
|
constructor(
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MutationResolvers, MutationRetryEventArgs } from '../../schema'
|
|
2
|
-
import { ActionsContext } from '../ActionsContext'
|
|
3
|
-
import { ActionsAuthorizationActions } from '../../../authorization'
|
|
4
|
-
import { EventsRepository } from '../../../dispatch/EventsRepository'
|
|
5
|
-
import { notify } from '../../../utils/notifyChannel'
|
|
1
|
+
import { MutationResolvers, MutationRetryEventArgs } from '../../schema/index.js'
|
|
2
|
+
import { ActionsContext } from '../ActionsContext.js'
|
|
3
|
+
import { ActionsAuthorizationActions } from '../../../authorization/index.js'
|
|
4
|
+
import { EventsRepository } from '../../../dispatch/EventsRepository.js'
|
|
5
|
+
import { notify } from '../../../utils/notifyChannel.js'
|
|
6
6
|
|
|
7
7
|
export class RetryEventMutationResolver implements MutationResolvers<ActionsContext> {
|
|
8
8
|
constructor(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MutationResolvers, MutationSetVariablesArgs } from '../../schema'
|
|
2
|
-
import { ActionsContext } from '../ActionsContext'
|
|
3
|
-
import { VariablesManager } from '../../../model/VariablesManager'
|
|
4
|
-
import { ActionsAuthorizationActions } from '../../../authorization'
|
|
1
|
+
import { MutationResolvers, MutationSetVariablesArgs } from '../../schema/index.js'
|
|
2
|
+
import { ActionsContext } from '../ActionsContext.js'
|
|
3
|
+
import { VariablesManager } from '../../../model/VariablesManager.js'
|
|
4
|
+
import { ActionsAuthorizationActions } from '../../../authorization/index.js'
|
|
5
5
|
|
|
6
6
|
export class SetVariablesMutationResolver implements MutationResolvers<ActionsContext> {
|
|
7
7
|
constructor(
|
|
@@ -12,7 +12,7 @@ export class SetVariablesMutationResolver implements MutationResolvers<ActionsCo
|
|
|
12
12
|
async setVariables(parent: unknown, { args }: MutationSetVariablesArgs, ctx: ActionsContext) {
|
|
13
13
|
await ctx.requireAccess(ActionsAuthorizationActions.VARIABLES_SET)
|
|
14
14
|
|
|
15
|
-
await this.variablesManager.setVariables(ctx.db, args)
|
|
15
|
+
await this.variablesManager.setVariables(ctx.db, args, ctx.project.slug)
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
18
|
ok: true,
|