Skip to content

VCST-5686: Add on-demand job cancellation - #3097

Open
OlegoO wants to merge 6 commits into
devfrom
feat/VCST-5686
Open

VCST-5686: Add on-demand job cancellation#3097
OlegoO wants to merge 6 commits into
devfrom
feat/VCST-5686

Conversation

@OlegoO

@OlegoO OlegoO commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Add on-demand job cancellation to the engine-agnostic background-jobs API.

Two default interface members on IBackgroundJob, plus the static BackgroundJob counterparts:

Task<bool> Cancel(string jobId, CancellationToken ct = default);  // default: false
bool SupportsCancellation { get; }

Description

References

QA-test:

Jira-link:

https://virtocommerce.atlassian.net/browse/VCST-5686

Artifact URL:


Note

Medium Risk
Public job API changes affect how callers stop in-flight work; defaults are safe, but real cancellation behavior depends on the engine implementation outside this diff.

Overview
Adds an engine-agnostic on-demand cancellation surface on IBackgroundJob (Cancel returning whether cancellation was requested, and SupportsCancellation), with default no-op behavior so existing engines keep working until they override. The static BackgroundJob facade gets matching Cancel and SupportsCancellation members that resolve IBackgroundJob through a scoped provider (uninitialized facade yields false for support, same pattern as enqueue).

Recurring schedules can now declare WithMaxRetryAttempts, which flows into EnqueueOptions on each trigger (combined with queue when set; still null options when neither queue nor retries are configured). IBackgroundJob XML documentation is trimmed on the interface; behavior of enqueue overloads is unchanged.

New unit tests assert recurring builder → EnqueueOptions wiring for retries, queue combination, and negative retry rejection.

Reviewed by Cursor Bugbot for commit 3559772. Bugbot is set up for automated code reviews on this repo. Configure here.

Image tag:
ghcr.io/VirtoCommerce/platform:3.1059.0-pr-3097-3559-vcst-5686-3559772a

Add on-demand job cancellation to the engine-agnostic background-jobs API.

Two default interface members on IBackgroundJob, plus the static BackgroundJob counterparts:

```cs
Task<bool> Cancel(string jobId, CancellationToken ct = default);  // default: false
bool SupportsCancellation { get; }
```
@OlegoO
OlegoO requested a review from basilkot August 6, 2026 12:58
OlegoO and others added 3 commits August 6, 2026 15:00
AddRecurringJob had no way to express [AutomaticRetry(Attempts = 0)], which
several migrated recurring jobs (image-tools ProcessAll, search IndexChangesJob)
carried under Hangfire: EnqueueOptions is built by the schedule builder, and the
builder only exposed the queue.

WithMaxRetryAttempts(n) flows into that EnqueueOptions, so a schedule can opt out
of retries — a scheduled run that failed is superseded by the next occurrence.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The cancellation commit dropped the XML docs from both Enqueue members and added
Cancel/SupportsCancellation with none, leaving the facade — the one type module
authors read before writing a job — undocumented.

Restores the Enqueue docs verbatim and documents the two new members: what Cancel
returns and why SupportsCancellation must be probed first, so an engine that
cannot cancel degrades visibly instead of accepting a request that does nothing.

Adds Platform.Core tests for the recurring schedule builder covering the new
WithMaxRetryAttempts alongside the existing queue option.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ OlegoO
❌ basilkot
You have signed the CLA already but the status is still pending? Let us recheck it.

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

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.

3 participants