一键导入
planforge-new-worker
Scaffold a background worker using BackgroundService with PeriodicTimer, structured logging, graceful shutdown, and health checks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold a background worker using BackgroundService with PeriodicTimer, structured logging, graceful shutdown, and health checks.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Run a comprehensive code review across architecture, security, testing, naming, and patterns. Invokes relevant reviewer agents in sequence. Use before merging features or at the end of a phase. With --quorum, dispatches multi-model analysis for higher confidence.
Audit UI components for WCAG 2.2 compliance, semantic HTML, ARIA labels, keyboard navigation, color contrast, and responsive design.
Audit API endpoints for backward compatibility, versioning, OpenAPI compliance, pagination, rate limiting, and RFC 9457 error responses.
Review code for architecture violations: layer separation, sync-over-async, missing CancellationToken, improper DI. Use for PR reviews or code audits.
Fix a bug using TDD: reproduce with a failing test first, then implement the fix, then verify. Prevents regressions.
Review CI/CD pipelines for best practices: environment promotion, secrets management, rollback strategies, build caching, and deployment safety.
| name | planforge-new-worker |
| description | Scaffold a background worker using BackgroundService with PeriodicTimer, structured logging, graceful shutdown, and health checks. |
| metadata | {"author":"plan-forge","source":".github/prompts/new-worker.prompt.md"} |
Scaffold a hosted background service following .NET patterns.
public sealed partial class {Name}Worker(
IServiceScopeFactory scopeFactory,
ILogger<{Name}Worker> logger) : BackgroundService
{
private static readonly TimeSpan Interval = TimeSpan.FromMinutes(5);
[LoggerMessage(Level = LogLevel.Information, Message = "{Name}Worker started — interval {Interval}")]
partial void LogStarted(TimeSpan interval);
[LoggerMessage(Level = LogLevel.Error, Message = "{Name}Worker iteration failed")]
partial void LogIterationFailed(Exception ex);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
LogStarted(Interval);
using var timer = new PeriodicTimer(Interval);
while (await timer.WaitForNextTickAsync(stoppingToken))
{
try
{
await using var scope = scopeFactory.CreateAsyncScope();
var service = scope.ServiceProvider.GetRequiredService<I{Name}Service>();
await service.ProcessAsync(stoppingToken);
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
break; // Graceful shutdown
}
catch (Exception ex)
{
LogIterationFailed(ex);
// Don't rethrow — keep the worker alive
}
}
}
}
// In Program.cs
builder.Services.AddHostedService<{Name}Worker>();
builder.Services.AddScoped<I{Name}Service, {Name}Service>();
public class {Name}HealthCheck(/* state */) : IHealthCheck
{
public Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context, CancellationToken ct = default)
{
var lastRun = /* get last successful run time */;
var isHealthy = DateTime.UtcNow - lastRun < TimeSpan.FromMinutes(15);
return Task.FromResult(isHealthy
? HealthCheckResult.Healthy($"Last run: {lastRun}")
: HealthCheckResult.Unhealthy($"Last run: {lastRun}"));
}
}
PeriodicTimer (not Task.Delay) for interval-based workIServiceScopeFactory)CancellationToken for graceful shutdown