Skip to content

feat(jobs): batch jobs container for a Manual Container Apps Job - #274

Open
svehera wants to merge 3 commits into
claude/project-thread-lm5368from
claude/project-thread-lm5368-jobs
Open

svehera wants to merge 3 commits into
claude/project-thread-lm5368from
claude/project-thread-lm5368-jobs

Conversation

@svehera

@svehera svehera commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Requested by Severyn · project thread

Part 3 of 3 of the background-jobs MVP. Stacked on #273: the diff here is only the jobs container. After #273 merges, this gets rebased onto main. Infra: TacticusPlanner/tacticus-planner-infra#37.

What

  • src/TacticusPlanner.Jobs: a generic-host console app (AddServiceDefaults for telemetry) built into its own image, tacticus-planner-jobs. It runs the job named by its first argument and exits.
    • Jobs are keyed IBatchJob registrations (JobRegistration.AddBatchJobs).
    • Refuses to run while migrations are pending, since the API applies them at startup.
    • Exit code is the execution result: 0 succeeded, 1 failed, 2 unknown job, 3 migrations pending.
    • Uses the planner-db-jobs-connection-string secret (pool of 2). It has no column-encryption key, so a job that touches an encrypted column fails fast.
  • One job, smoke: logs the applied-migration and profile counts. It proves the image, the connection string and the private network path work.
  • Dockerfile: same pinned SDK and chiseled aspnet digests as the API, locked restore, runtime sized for 0.25 vCPU / 0.5 GiB. CMD ["smoke"].
  • CI/CD
    • _publish-api.yml takes repository and dockerfile inputs (defaults stay the API), with a gha cache scope per image.
    • CD Stage and CD Prod add a "Publish jobs" job. Prod reuses the main-commit image the same way it does for the API.
    • _deploy-api.yml takes an optional jobs-image input, checks it is an immutable tacticus-planner-jobs@sha256 reference, and runs az containerapp job update --image once the API revision is healthy. If CONTAINER_APP_JOB_NAME is unset, or the job is missing or not readable yet (ResourceNotFound / AuthorizationFailed), the step is skipped with a warning and a summary note, so CD stays green before the infra steps below.
    • _build-api.yml also builds the jobs image when area:docker is set; plus a labeler area:jobs label and a Dependabot docker entry in the dotnet-sdk group.
  • tests/TacticusPlanner.Jobs.Tests: 5 runner cases with fakes, plus a Testcontainers test for unmigrated (exit 3) and migrated (exit 0) databases.
  • README "Batch jobs container" (how to start an execution and how to add a job), AGENTS.md, OpenSpec tasks/proposal.

Validation

  • TacticusPlanner.Jobs.Tests: 7/7 passed locally. Full suite left to CI.
  • dotnet format --verify-no-changes clean; dotnet restore --locked-mode clean; Release dotnet publish of the Jobs project OK.
  • Ran the published host against a throwaway Postgres: an unknown job exits 2, and smoke against an unmigrated database exits 3.
  • Workflow YAML parses, and the deploy step scripts pass bash -n. I could not run actionlint or docker build here: the sandbox proxy's CA isn't trusted inside Docker, and the API image fails the same way. CI's image build covers it.

Rollout (after this merges and CD publishes the first jobs image)

  1. In tacticus-planner-infra: deploy workload --env stg --action apply --image <api digest> --jobs-image <jobs digest>. This creates caj-tp-jobs-stg.
  2. access post --env stg grants the deploy identity access to the job. From then on, CD updates the job's image.
  3. az containerapp job start --name caj-tp-jobs-stg --resource-group rg-tp-stg, and check that the execution succeeded.
  4. Repeat for prod with --confirm prod.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RikpRHXQe5CFoQVZgczdDm

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@svehera svehera self-assigned this Nov 26, 2026
A separate console host and image, tacticus-planner-jobs, that runs one
named batch job per execution and exits. The only job is `smoke`, which
proves the image, the jobs connection string and the private network path.
The runner refuses to run while migrations are pending and reports the
outcome as its exit code.

CD Stage and CD Prod publish the image beside the API image and point the
Container Apps Job at it once the API revision is healthy; until the infra
has created the job and granted access, that step is skipped with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RikpRHXQe5CFoQVZgczdDm
@svehera
svehera force-pushed the claude/project-thread-lm5368-jobs branch from 5bc36dd to ba54846 Compare November 26, 2026 23:31
@svehera svehera changed the title feat(jobs): TacticusPlanner.Jobs container for Container Apps Jobs feat(jobs): batch jobs container for a Manual Container Apps Job Nov 26, 2026
@svehera
svehera marked this pull request as ready for review November 26, 2026 23:32
@svehera
svehera added this pull request to stack #275 November 27, 2026 12:30
…d-lm5368-jobs

# Conflicts:
#	openspec/changes/add-background-jobs/proposal.md
@github-actions github-actions Bot added ci dependencies Pull requests that update a dependency file area:docker area:jobs labels Nov 27, 2026
Comment on lines +47 to +51
catch (Exception exception)
{
LogFailed(logger, exception, name);
return Failed;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional. This is the process boundary of the batch host. Any exception a job throws must be logged, with the job name, to Application Insights and turned into exit code 1, which is what marks the Container Apps Job execution as failed. Letting it escape would crash the host without the structured log. Nothing is swallowed here: the job's own code still handles the specific exceptions it expects. Leaving it as is.


Generated by Claude Code

…d-lm5368-jobs

# Conflicts:
#	openspec/changes/add-background-jobs/proposal.md
@github-code-quality

github-code-quality Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / coverage/api

claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
23% 23% 0%
View coverage of the 6 most impacted files.
File claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
home/runner/wor...ountEndpoint.cs 38% 34% -4%
_/src/TacticusP...or/Logging.g.cs 18% 18% 0%
home/runner/wor....Api/Program.cs 96% 96% 0%
home/runner/wor...ncyInjection.cs 0% 59% +59%
home/runner/wor...yDeletionJob.cs 0% 100% +100%
home/runner/wor...dJobsOptions.cs 0% 100% +100%

C# / coverage/game-catalog

claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
93% 93% 0%

C# / coverage/api-integration

claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
94% 94% 0%
View coverage of the 8 most impacted files.
File claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
home/runner/wor...ntPlanWriter.cs 97% 86% -11%
home/runner/wor....Api/Program.cs 99% 99% 0%
home/runner/wor...ountEndpoint.cs 100% 100% 0%
_/src/TacticusP...or/Logging.g.cs 47% 50% +3%
home/runner/wor...ntityDeleter.cs 0% 20% +20%
home/runner/wor...ncyInjection.cs 0% 100% +100%
home/runner/wor...yDeletionJob.cs 0% 100% +100%
home/runner/wor...dJobsOptions.cs 0% 100% +100%

C# / coverage/persistence

claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
76% 76% 0%
View coverage of the 4 most impacted files.
File claude/project-threa... 00830cd claude/project-threa... 1696a2b +/-
home/runner/wor...OrderService.cs 73% 72% -1%
home/runner/wor...yDeletionJob.cs 0% 0% 0%
home/runner/wor...dJobsOptions.cs 0% 0% 0%
home/runner/wor...ncyInjection.cs 0% 0% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 27, 2026 12:45 UTC

This branch has not been deployed

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

Labels

area:docker area:jobs ci dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants