add-background-job
Skill234 starsChanged 3 months agoMITView on GitHub
Add a Hangfire background job (recurring or one-time)
1 other project uses a version of this.
Adopted by
Most recently taken up by
- purplefish-ai/factory-factorytheir own version, first seen Nov 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- purplefish-ai/factory-factory★ 54same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository29 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- add-aspire-depSkill
- add-ci-areaSkill
- add-email-templateSkill
- add-env-varSkill
- add-options-classSkill
- add-permissionSkill
- add-rate-limitSkill
- address-reviewSkill
- add-testSkill
- backend-conventionsSkill
- create-issueSkill
- create-prSkill
- create-releaseSkill
- frontend-conventionsSkill
- gen-typesSkill
- infra-conventionsSkill
- init-verifySkill
- manage-file-storageSkill
- new-endpointSkill
- new-entitySkill
- new-featureSkill
- new-pageSkill
- polish-uiSkill
- review-dependabotSkill
- review-designSkill
- review-prSkill
- security-conventionsSkill
- verifySkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
2. Register in DI: - add two lines to src/backend/MyProject.Infrastructure/Features/Jobs/Extensions/ServiceCollectionExtensions.cs:
- Very specific: line 81
All parameters must be JSON-serializable (Hangfire persists them).
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Adds a recurring or one-time Hangfire background job.
Recurring Job
1. Create the job class in src/backend/MyProject.Infrastructure/Features/Jobs/RecurringJobs/{JobName}Job.cs:
using Hangfire;
using Microsoft.Extensions.Logging;
namespace MyProject.Infrastructure.Features.Jobs.RecurringJobs;
/// <summary>
/// Brief description of what this job does and why.
/// </summary>
internal sealed class MyCleanupJob(
MyProjectDbContext dbContext,
TimeProvider timeProvider,
ILogger<MyCleanupJob> logger) : IRecurringJobDefinition
{
/// <inheritdoc />
public string JobId => "my-cleanup";
/// <inheritdoc />
public string CronExpression => Cron.Daily();
/// <inheritdoc />
public async Task ExecuteAsync()
{
// Job logic here - each execution gets its own DI scope
logger.LogInformation("Job completed");
}
}Key conventions:
- Mark
internal sealed, use primary constructor - Descriptive
JobId(kebab-case, e.g."expired-token-cleanup") Hangfire.Cronhelpers:Cron.Hourly(),Cron.Daily(),Cron.Weekly()
2. Register in DI - add two lines to src/backend/MyProject.Infrastructure/Features/Jobs/Extensions/ServiceCollectionExtensions.cs:
services.AddScoped<MyCleanupJob>();
services.AddScoped<IRecurringJobDefinition>(sp => sp.GetRequiredService<MyCleanupJob>());3. Verify: dotnet build src/backend/MyProject.slnx
UseJobScheduling() discovers all IRecurringJobDefinition implementations automatically. The job appears in admin panel at /admin/jobs. Pause state persists to DB (hangfire.pausedjobs).
Configuration via appsettings.json: "JobScheduling": { "Enabled": true, "WorkerCount": 4 }. Dev dashboard at http://localhost:8080/hangfire.
One-Time Job
For ad-hoc background work (call API, process file, generate report), use IBackgroundJobClient directly.
Note: transactional emails are already queued automatically - ITemplatedEmailSender.SendSafeAsync() routes through BackgroundEmailService -> EmailDeliveryJob (Features/Email/Jobs/) whenever email and job scheduling are both enabled. Do not wrap email sends in another job.
1. Create the job class in src/backend/MyProject.Infrastructure/Features/{Feature}/Jobs/ (or Features/Jobs/ for cross-cutting jobs):
internal sealed class ReportGenerationJob(
IReportService reportService,
ILogger<ReportGenerationJob> logger)
{
[AutomaticRetry(Attempts = 3, DelaysInSeconds = [30, 120, 600])]
public async Task ExecuteAsync(Guid reportId, CancellationToken cancellationToken)
{
await reportService.GenerateAsync(reportId, cancellationToken);
logger.LogInformation("Generated report '{ReportId}'", reportId);
}
}All parameters must be JSON-serializable (Hangfire persists them). Never pass IServiceProvider, HttpContext, or DbContext as arguments. A trailing CancellationToken parameter is injected by Hangfire (server shutdown) - pass CancellationToken.None in the enqueue expression.
Let exceptions propagate - [AutomaticRetry] only retries when the method throws. Retries re-run the whole method, so keep it idempotent.
2. Register: services.AddScoped<ReportGenerationJob>();
3. Enqueue:
// Fire-and-forget
backgroundJobClient.Enqueue<ReportGenerationJob>(job => job.ExecuteAsync(reportId, CancellationToken.None));
// Delayed
backgroundJobClient.Schedule<ReportGenerationJob>(job => job.ExecuteAsync(reportId, CancellationToken.None), TimeSpan.FromMinutes(30));Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

