elsa-workflows / elsa-workflows/elsa-core

Generic Task Reporter

Open
#7,068 0 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Feature Request

### Problem Overview
Creating custom version of the RunTask activity do not have to require a custom implementation of TaskReporter if the current TaskReporter (and ITaskReporter) is made generic.

### Proposed Solution
ITaskReporter could have a generic type T where T implements IActivity. In the implementation of task reporter, the activity type name could just be ActivityTypeNameHelper.GenerateTypeName() instead of hard-coded for the RunTask Activity. Seems like an easy patch to make at least the bookmark resumption work for other activities without needing to make a whole new custom TaskReport implementation.

Though that raises the point of the Input key. In order to completely remove all references to the RunTask activity directly in the implementation of TaskReporter, perhaps T could be restricted to some kind of new Acitvity Interface type, ITaskActivity, which simply forces all Activities of type ITaskActivity to implement a string InputKey (and probably TaskName as well) which can then be used in this new generic Task Reporter.

### Alternative Solutions
Creating a new implementation of TaskReporter as discussed in discussion #6090

### Use Cases
Less code management when creating new implementations of the RunTask activity.

### Impact of Feature
Very re-usable component that will speed up development time for consumers of Elsa.

### Visuals and Mockups
```
public interface ITaskReporter where T : IActivity
{
Task ReportCompletionAsync(string taskId, object? result = default, CancellationToken cancellationToken = default);
}

public class TaskReporter(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulusHasher)
: ITaskReporter where T : IActivity
{
public async Task ReportCompletionAsync(string taskId, object? result = null, CancellationToken cancellationToken = default)
{
RunTaskStimulus stimulus = new(taskId, null!);

Dictionary input = new() { [RunTask.InputKey] = result! };

string activityTypeName = ActivityTypeNameHelper.GenerateTypeName();
NewBookmarkQueueItem bookmarkQueueItem = new()
{
ActivityTypeName = activityTypeName,
StimulusHash = stimulusHasher.Hash(activityTypeName, stimulus),
Options = new ResumeBookmarkOptions { Input = input }
};

await bookmarkQueue.EnqueueAsync(bookmarkQueueItem, cancellationToken);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.