Skip to content

feat(cli): Composite startup verbs for the flagsmith entrypoint#240

Merged
khvn26 merged 6 commits into
mainfrom
feat/composite-startup-verbs
Jul 3, 2026
Merged

feat(cli): Composite startup verbs for the flagsmith entrypoint#240
khvn26 merged 6 commits into
mainfrom
feat/composite-startup-verbs

Conversation

@khvn26

@khvn26 khvn26 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Changes

Closes #239.

In this PR, we add the composite startup verbs to the flagsmith CLI, fully compatible with Core API's run-docker.sh.

New flagsmith verbs:

  • serve
  • migrate
  • run-task-processor
  • migrate-and-serve

They mirror run-docker.sh's sequencing exactly, but run in a single process, so the Django app registry is initialised once instead of once per manage.py subprocess. They stay generic — no Core-API specifics — driven by settings the consuming app provides:

  • FLAGSMITH_MIGRATE_DATABASES (default ["default"]) — databases the migrate step applies, in order
  • FLAGSMITH_WAIT_FOR_MIGRATIONS_DATABASES (default ["default"]) — databases run-task-processor waits on
  • FLAGSMITH_STARTUP_COMMANDS (default []) — commands run between migrate and serve in migrate-and-serve

SKIP_WAIT_FOR_DB is honoured in the verb layer. The server hand-off goes through the existing start command via the management CLI path (not call_command, which can't pass through start's gunicorn arguments alongside its subparsers).

Separately, the task processor's worker tuning arguments (--numthreads, --sleepintervalms, --graceperiodms, --queuepopsize) now default from the TASK_PROCESSOR_* environment variables, falling back to the values run-docker.sh used, so that tuning survives the move to the entrypoint. environs is added to the task-processor extra, which now reads it.

The README documents the new verbs and their settings and environment variables.

How did you test this code?

Unit tests cover each verb's exact call sequence, the settings-driven database lists, the bare-vs-targeted migrate split, SKIP_WAIT_FOR_DB, argument pass-through, dispatch routing, and the task processor env defaults, including the TASK_PROCESSOR_SLEEP_INTERVAL fallback and precedence.

khvn26 added 3 commits June 26, 2026 19:44
Add serve, migrate, run-task-processor and migrate-and-serve verbs to the
`flagsmith` CLI, mirroring the role sequencing Core API's run-docker.sh
performs in shell but running in a single process so the Django app registry
is initialised once instead of per step.

The verbs stay generic: the databases to migrate or wait for, and any extra
startup commands, are driven by settings the consuming app provides
(FLAGSMITH_MIGRATE_DATABASES, FLAGSMITH_WAIT_FOR_MIGRATIONS_DATABASES,
FLAGSMITH_STARTUP_COMMANDS).

beep boop
Default --numthreads, --sleepintervalms, --graceperiodms and --queuepopsize
from the TASK_PROCESSOR_* environment variables (falling back to the values
run-docker.sh used), so the tuning survives the move to the `flagsmith`
entrypoint. Adds environs to the task-processor extra, which now reads it.

beep boop
@khvn26 khvn26 requested a review from a team as a code owner June 29, 2026 03:30
@khvn26 khvn26 requested review from emyller and removed request for a team June 29, 2026 03:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces composite startup commands to the flagsmith entrypoint to handle startup sequencing in a single process, and adds environment variable configuration for the task processor. The review feedback highlights a critical bug in how the legacy TASK_PROCESSOR_SLEEP_INTERVAL (seconds) is parsed as milliseconds, which can cause validation failures or high CPU usage. Additionally, the feedback suggests splitting startup commands with arguments using shlex.split to prevent execution failures, updating the unit tests accordingly, and clarifying the README documentation.

Comment thread src/task_processor/utils.py Outdated
Comment thread src/common/core/cli/run.py
Comment thread tests/unit/task_processor/test_unit_task_processor_utils.py
Comment thread README.md
@codecov-commenter

codecov-commenter commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.56%. Comparing base (819921a) to head (10cdd9a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   97.39%   97.56%   +0.16%     
==========================================
  Files         104      108       +4     
  Lines        4613     4757     +144     
==========================================
+ Hits         4493     4641     +148     
+ Misses        120      116       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

FLAGSMITH_STARTUP_COMMANDS entries are command strings; passing an entry with
arguments (e.g. "bootstrap --skip-fixtures") as a single argv element makes
Django treat the whole string as an unknown subcommand. Shell-split each entry
with shlex before dispatch.

beep boop
@khvn26 khvn26 changed the title feat: Composite startup verbs for the flagsmith entrypoint feat(cli): Composite startup verbs for the flagsmith entrypoint Jun 30, 2026

@matthewelwell matthewelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple of initial comments. Not quite ready to approve until I have answers, but not blocking so not worth a 'request changes' status.

Comment thread src/common/core/cli/run.py
Comment thread src/task_processor/utils.py Outdated
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1af09852-e33e-4c03-a959-8aa7e1a6d2de

📥 Commits

Reviewing files that changed from the base of the PR and between 1729be2 and 10cdd9a.

📒 Files selected for processing (1)
  • src/task_processor/utils.py

📝 Walkthrough

Walkthrough

This PR adds composite startup verbs to the flagsmith CLI, wiring new serve, migrate, run-task-processor, and migrate-and-serve commands into common.core.main. It introduces startup orchestration in common.core.cli.run, adds environment-driven defaults for task processor CLI options, documents the new commands in the README, and updates unit tests for dispatch and argument handling. It also adds environs as an optional dependency.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as flagsmith CLI
  participant main as common.core.main
  participant run as common.core.cli.run
  participant waitfordb as waitfordb command
  participant django as django_execute_from_command_line

  CLI->>main: execute_from_command_line(argv)
  main->>run: dispatch startup subcommand
  run->>waitfordb: wait for DB / migrations when needed
  run->>django: migrate / createcachetable / start api / task-processor
Loading

Related issues: None specified in the provided diff.
Related PRs: None specified in the provided diff.
Suggested labels: enhancement, cli, task-processor
Suggested reviewers: None specified in the provided diff.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c54f0626-2423-4042-9557-c003ef34d47d

📥 Commits

Reviewing files that changed from the base of the PR and between 819921a and d955e51.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • README.md
  • pyproject.toml
  • src/common/core/cli/run.py
  • src/common/core/main.py
  • src/task_processor/constants.py
  • src/task_processor/utils.py
  • tests/unit/common/core/test_main.py
  • tests/unit/common/core/test_run.py
  • tests/unit/task_processor/test_unit_task_processor_utils.py

Comment thread src/common/core/cli/run.py
Comment thread src/common/core/cli/run.py
Comment thread src/task_processor/utils.py
Comment thread tests/unit/common/core/test_main.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 34adf54e-6668-4be3-97e0-4db00ea6f748

📥 Commits

Reviewing files that changed from the base of the PR and between d955e51 and 1729be2.

📒 Files selected for processing (1)
  • src/task_processor/utils.py

Comment thread src/task_processor/utils.py Outdated
@khvn26 khvn26 force-pushed the feat/composite-startup-verbs branch from 1729be2 to 10cdd9a Compare July 3, 2026 11:43
@khvn26 khvn26 merged commit b2f15c2 into main Jul 3, 2026
4 checks passed
@khvn26 khvn26 deleted the feat/composite-startup-verbs branch July 3, 2026 14:23
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.

Replace Core's run-docker.sh

4 participants