Skip to content

Commit

Permalink
Add optional refresh parameter (#5876)
Browse files Browse the repository at this point in the history
* Add optional refresh parameter

Renamed several `RefreshDescriptors` methods to `RefreshDescriptorsAsync` to reflect their asynchronous nature consistently. Added an optional refresh parameter in the `ListActivityDescriptorsRequest` class and updated related endpoints to handle this parameter, triggering a registry refresh if necessary.

* Update version to 3.2.0-rc5 in GitHub Actions

Modified the `packages.yml` workflow to change the version from `3.2.0-rc4` to `3.2.0-rc5` for non-tagged releases. This ensures version consistency with the new release candidate.
  • Loading branch information
sfmskywalker committed Aug 12, 2024
1 parent ef2dfd3 commit c8669d1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
TAG_NAME=${TAG_NAME#refs/tags/} # remove the refs/tags/ prefix
echo "VERSION=${TAG_NAME}" >> $GITHUB_ENV
else
echo "VERSION=3.2.0-rc4.${{github.run_number}}" >> $GITHUB_ENV
echo "VERSION=3.2.0-rc5.${{github.run_number}}" >> $GITHUB_ENV
fi
- name: Set up JDK 17
uses: actions/setup-java@v2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Refit;

namespace Elsa.Api.Client.Resources.ActivityDescriptors.Requests;

/// <summary>
/// Represents a request to list activity descriptors.
/// </summary>
public record ListActivityDescriptorsRequest;
public class ListActivityDescriptorsRequest
{
/// Whether to refresh the activity descriptors or not.
[Query] public bool Refresh { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
using Elsa.Abstractions;
using Elsa.Workflows.Contracts;
using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity;
using Elsa.Workflows.Management.Contracts;
using JetBrains.Annotations;

namespace Elsa.Workflows.Api.Endpoints.ActivityDescriptors.List;

[PublicAPI]
internal class List(IActivityRegistry registry) : ElsaEndpointWithoutRequest<Response>
internal class List(IActivityRegistry registry, IActivityRegistryPopulator registryPopulator, WorkflowDefinitionActivityProvider workflowDefinitionActivityProvider) : ElsaEndpointWithoutRequest<Response>
{
public override void Configure()
{
Get("/descriptors/activities");
ConfigurePermissions("read:*", "read:activity-descriptors");
}

public override Task<Response> ExecuteAsync(CancellationToken cancellationToken)
public override async Task<Response> ExecuteAsync(CancellationToken cancellationToken)
{
var forceRefresh = Query<bool>("refresh", false);

if (forceRefresh)
await registryPopulator.PopulateRegistryAsync(cancellationToken);

var descriptors = registry.ListAll().ToList();
var response = new Response(descriptors);

return Task.FromResult(response);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ public interface IActivityRegistry : IActivityProvider
/// <param name="activityProviders">The activity providers used to retrieve the descriptors.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task RefreshDescriptors(IEnumerable<IActivityProvider> activityProviders, CancellationToken cancellationToken = default);
Task RefreshDescriptorsAsync(IEnumerable<IActivityProvider> activityProviders, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task RegisterAsync(IEnumerable<Type> activityTypes, CancellationTok
public ValueTask<IEnumerable<ActivityDescriptor>> GetDescriptorsAsync(CancellationToken cancellationToken = default) => new(_manualActivityDescriptors);

/// <inheritdoc />
public async Task RefreshDescriptors(IEnumerable<IActivityProvider> activityProviders, CancellationToken cancellationToken = default)
public async Task RefreshDescriptorsAsync(IEnumerable<IActivityProvider> activityProviders, CancellationToken cancellationToken = default)
{
var providersDictionary = new ConcurrentDictionary<Type, ICollection<ActivityDescriptor>>();
var activityDescriptors = new ConcurrentDictionary<(string Type, int Version), ActivityDescriptor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IEnumerable<ActivityDescriptor> FindMany(Func<ActivityDescriptor, bool> p
if (descriptor is not null)
return descriptor;

await activityRegistry.RefreshDescriptors(providers);
await activityRegistry.RefreshDescriptorsAsync(providers);
return findPredicate.Invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task HandleAsync(WorkflowDefinitionVersionsUpdated notification, Ca

private Task UpdateDefinition(string id, bool? usableAsActivity)
{
// Once a workflow has been published it should remain in the activity registry unless no longer being marked as an activity.
// Once a workflow has been published, it should remain in the activity registry unless no longer being marked as an activity.
if (usableAsActivity.GetValueOrDefault())
return workflowDefinitionActivityRegistryUpdater.AddToRegistry(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class ActivityRegistryPopulator(IEnumerable<IActivityProvider> providers,
/// <inheritdoc />
public async Task PopulateRegistryAsync(CancellationToken cancellationToken)
{
await registry.RefreshDescriptors(providers, cancellationToken);
await registry.RefreshDescriptorsAsync(providers, cancellationToken);
}
}

0 comments on commit c8669d1

Please sign in to comment.