Skip to content

Invocable With PreventOverlap #446

@jamesmh

Description

@jamesmh

Context

Right now, coravel scheduled invocables can be tagged with the "prevent overlap" method that will ensure that the scheduler will only launch / execute an invocable if no other instance of that invocable is running. In other words, only 1 instance should ever be running at any given moment.

The queue functionality is able to queue an invocable, however it does not currently support the "prevent overlap" functionality.

What we want to do is be able to configure an invocable so that it will have "prevent overlapping" attached to the invocable globally, so that regardless if whether it is executed by the scheduler or invoked via the queue (IQueue) it will skip executing if another instance is running.

The logic to check the mutex exists in the scheduler. However, the queue doesn't have that logic, but it should be very similar.

Implementation / requirements

We want to create the following + have the following requirements:

  • Create a new way to mark an invocable with "prevent overlapping": The interface should be a static method like:
    • public static IServiceProvider PreventOverlapping<TInvocable>(this IServiceProvider provider, string uniqueIdentifier)
  • We'll also need a new singleton class to store this new information. This can be a new ICoravelGlobalConfiguration interface, with an implementation that is registered as a singleton in DI.
  • When calling PreventOverlapping, we'll get the instance of the ICoravelGlobalConfiguration and call a method to store the new prevent overlapping entry.
  • The scheduler and queue will now have the ability to call bool ICoravelGlobalConfguration.TryGetPreventOverlapping<TInvocable>(string uniqueIdentifier). This method will return true if the invocable type has been set. If it has been set, then the further logic can use the Mutex (as the existing logic in the scheduler is doing) to check if the invocable is locked/unlocked.
  • The scheduler logic will need an extra if statement to check if there's a global prevent overlapping for an invocable (but this shouldn't apply if the scheduled event is not an invocable but an action/function.
  • The Queue will need the logic that's in the scheduler "copied" into the queue logic, but will check against ICoravelGlobalConfiguration.TryGetPreventOverlapping only. If the mutex is locked for this invocable, we consume the job but don't execute it (e.g. skip it).

Remember to add tests and follow the existing conventions for tests!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions