Comments (4)
To subscribe to workflow and activity events in Elsa 3.0, you can use the event handling features provided by Elsa to listen for specific events and react accordingly. Elsa 3.0 has a robust event system that allows you to subscribe to various workflow-related events, such as when an activity is executed, when a workflow is started, or when a workflow is halted.
Here is an example code snippet that demonstrates how to subscribe to workflow and activity events:
public class MyWorkflowEventHandler
{
private readonly IEventPublisher _eventPublisher;
public MyWorkflowEventHandler(IEventPublisher eventPublisher)
{
_eventPublisher = eventPublisher;
}
public void Subscribe()
{
_eventPublisher.Subscribe<WorkflowStarted>(OnWorkflowStarted);
_eventPublisher.Subscribe<WorkflowCompleted>(OnWorkflowCompleted);
_eventPublisher.Subscribe<ActivityExecuted>(OnActivityExecuted);
_eventPublisher.Subscribe<ActivityFaulted>(OnActivityFaulted);
}
private void OnWorkflowStarted(WorkflowStarted context)
{
// Handle the workflow started event
Console.WriteLine($"Workflow {context.WorkflowInstanceId} started.");
}
private void OnWorkflowCompleted(WorkflowCompleted context)
{
// Handle the workflow completed event
Console.WriteLine($"Workflow {context.WorkflowInstanceId} completed.");
}
private void OnActivityExecuted(ActivityExecuted context)
{
// Handle the activity executed event
Console.WriteLine($"Activity {context.ActivityId} executed in workflow {context.WorkflowInstanceId}.");
}
private void OnActivityFaulted(ActivityFaulted context)
{
// Handle the activity faulted event
Console.WriteLine($"Activity {context.ActivityId} faulted in workflow {context.WorkflowInstanceId}.");
}
}
In this example, IEventPublisher
is used to subscribe to various events. You would need to implement the event handlers (OnWorkflowStarted
, OnWorkflowCompleted
, OnActivityExecuted
, OnActivityFaulted
) to perform the actions you want when these events occur.
Please note that the exact implementation details may vary depending on the version of Elsa you are using and the specific requirements of your application. For the most accurate and up-to-date information, you should refer to the official Elsa documentation and examples.
from elsa-core.
bu there is no "Subscribe" method in "IEventPublisher". @noxe @petedavis
from elsa-core.
@coolshun
I did it by implementing my own event handler
public class WorkflowProgressTracker :
INotificationHandler<WorkflowExecuted>,
INotificationHandler<WorkflowExecuting>,
INotificationHandler<WorkflowFinished>,
INotificationHandler<WorkflowStarted>
{
// implementation omitted
}
then register all your handlers in startup by single call
services.AddNotificationHandlersFrom<Program>();
Note
Example above works on Elsa Server 3.0.6
The list of available events
Elsa.Alterations.Core.Notifications.AlterationJobCompleted
Elsa.Alterations.Core.Notifications.AlterationPlanSubmitted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionCreated
Elsa.Workflows.Management.Notifications.WorkflowDefinitionDeleted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionDeleting
Elsa.Workflows.Management.Notifications.WorkflowDefinitionPublished
Elsa.Workflows.Management.Notifications.WorkflowDefinitionPublishing
Elsa.Workflows.Management.Notifications.WorkflowDefinitionRetracted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionRetracting
Elsa.Workflows.Management.Notifications.WorkflowDefinitionVersionDeleted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionVersionDeleting
Elsa.Workflows.Management.Notifications.WorkflowDefinitionVersionsDeleted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionVersionsDeleting
Elsa.Workflows.Management.Notifications.WorkflowDefinitionsDeleted
Elsa.Workflows.Management.Notifications.WorkflowDefinitionsDeleting
Elsa.Workflows.Management.Notifications.WorkflowInstanceSaved
Elsa.Workflows.Management.Notifications.WorkflowInstancesDeleted
Elsa.Workflows.Management.Notifications.WorkflowInstancesDeleting
Elsa.Workflows.Notifications.ActivityCancelled
Elsa.Workflows.Notifications.ActivityExecuted
Elsa.Workflows.Notifications.ActivityExecuting
Elsa.Workflows.Notifications.SafeSerializerDeserializing
Elsa.Workflows.Notifications.SafeSerializerSerializing
Elsa.Workflows.Notifications.SerializingWorkflowState
Elsa.Workflows.Notifications.WorkflowExecuted
Elsa.Workflows.Notifications.WorkflowExecuting
Elsa.Workflows.Notifications.WorkflowFinished
Elsa.Workflows.Notifications.WorkflowStarted
Elsa.Workflows.Runtime.Notifications.ActivityExecutionLogUpdated
Elsa.Workflows.Runtime.Notifications.ActivityExecutionRecordDeleted
Elsa.Workflows.Runtime.Notifications.ActivityExecutionRecordUpdated
Elsa.Workflows.Runtime.Notifications.BookmarksDeleted
Elsa.Workflows.Runtime.Notifications.BookmarksDeleting
Elsa.Workflows.Runtime.Notifications.RunTaskRequest
Elsa.Workflows.Runtime.Notifications.WorkflowBookmarksDeleted
Elsa.Workflows.Runtime.Notifications.WorkflowBookmarksIndexed
Elsa.Workflows.Runtime.Notifications.WorkflowBookmarksPersisted
Elsa.Workflows.Runtime.Notifications.WorkflowExecutionLogUpdated
Elsa.Workflows.Runtime.Notifications.WorkflowInboxMessageReceived
Elsa.Workflows.Runtime.Notifications.WorkflowTriggersIndexed
from elsa-core.
@msavencov I have another question, can you help me? #5131 How to create a workflow instance without immediately executing it and execut it later?
from elsa-core.
Related Issues (20)
- [CHORE] Improve warning for unordered 'Skip'/'Take' operations in EF Core queries HOT 1
- [PERF] Optimize WorkflowDefinitionActivity Loading with Caching HOT 1
- [BUG] Nested Workflow Does Not Honor Logging Persistence Settings HOT 1
- [PERF] Enhance Scalability and Simplify Workflow Execution with Proto.Actor HOT 1
- [TEST] Enhance Testing Framework for Extended Integration and E2E Testing HOT 1
- Deprecated reference dlls. HOT 1
- CSharp expression - Access last activity output result HOT 3
- [PERF] Journal Data is logging to redundant information in WorkflowExecutionLogRecords HOT 2
- [ENH] Support TypeName Overriding in IActivityDescriptorModifier Without Breaking Workflow Builder API HOT 1
- Elsa 3 error executing csharp expression - The memory block 'Elsa.Expressions.Models.MemoryBlockReference' does not exist HOT 2
- Elsa 3.1 - csharp script - extend the scripting capabilities to include custom types HOT 1
- [BUG] Http Response activity doesnt send the response before completing. HOT 2
- [BUG] Problem with WriteHttpResponse Activity on External Workflow Start HOT 3
- [ENH] Display Log Persistence Mode in Workflow Instance Viewer
- [PERF] Cache JavaScript AST for Workflow Definitions HOT 1
- [BUG]An error in example of c# expression in documentation. HOT 1
- [BUG] Need to clone serializer to adjust options for context
- How to implement repeated execution of HttpEndpoint in Elsa3? HOT 2
- How to make the activity execute automatically after the process is restored? HOT 1
- [BUG] toJson() incorrectly decodes encoded characters HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elsa-core.