Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 20, 2025

This PR implements global prevent overlapping functionality that allows invocables to be configured to prevent overlapping executions across both the scheduler and queue systems.

Problem

Previously, prevent overlapping was only available at the individual scheduled event level using .PreventOverlapping("identifier"). There was no way to configure an invocable type globally so that it would prevent overlapping regardless of whether it was executed by the scheduler or queued via IQueue.

Solution

Added a new global configuration system that allows invocables to be marked for prevent overlapping at the type level:

// Configure global prevent overlapping for an invocable type
services.AddScheduler();
services.AddQueue();

var provider = services.BuildServiceProvider();
provider.PreventOverlapping<MyInvocable>("my-unique-identifier");

// Now MyInvocable will prevent overlapping in both contexts:
scheduler.Schedule<MyInvocable>().EveryMinute(); // Prevents overlapping
queue.QueueInvocable<MyInvocable>(); // Also prevents overlapping

Key Features

  • Global Configuration: New ICoravelGlobalConfiguration service manages invocable-level settings
  • Extension Method: provider.PreventOverlapping<TInvocable>("uniqueId") for easy configuration
  • Dual Support: Works seamlessly with both scheduled tasks and queued tasks
  • Priority System: Event-level prevent overlapping takes precedence over global configuration
  • Backwards Compatibility: All existing functionality preserved with optional constructor overloads

Implementation Details

  • Added ICoravelGlobalConfiguration interface and CoravelGlobalConfiguration implementation
  • Updated both Scheduler and Queue to check global configuration using shared mutex
  • Queue implementation consumes overlapping jobs but skips execution (as specified in requirements)
  • Uses reflection for type-safe generic method calls with runtime Type objects
  • Automatically registered when using AddScheduler() or AddQueue()

Testing

  • All existing 1008 tests continue to pass
  • Added 6 comprehensive new tests covering:
    • Scheduler global prevent overlapping
    • Queue global prevent overlapping
    • Service provider configuration
    • Error handling for invalid configurations
    • Priority between event-level and global configurations

Fixes #446.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Invocable With PreventOverlap Add global prevent overlapping functionality for invocables Jul 20, 2025
Copilot AI requested a review from jamesmh July 20, 2025 03:42
Copilot finished work on behalf of jamesmh July 20, 2025 03:42
@jchilton
Copy link

jchilton commented Aug 20, 2025

Researching a use case led me here. My use case requires multiple invocables to be mutually exclusive, so that any of N types of invocables must run sequentially. If/when the PR is merged, would you recommend those types implement a common interface to achieve that? Or, can you advise as to a recommended pattern within the PR's paradigm? Thanks, I'm glad to see work on this. *** Edit: Copilot advises that the string lock identifier will lock unilaterally, regardless of what the generic parameter is. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invocable With PreventOverlap

3 participants