Skip to content

Added "fetch and lock steps", a necessary operation for automations#28348

Closed
EvanHahn wants to merge 1 commit into
mainfrom
fetch-and-lock-automation-steps
Closed

Added "fetch and lock steps", a necessary operation for automations#28348
EvanHahn wants to merge 1 commit into
mainfrom
fetch-and-lock-automation-steps

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented Jun 3, 2026

towards https://linear.app/ghost/issue/NY-1286
ref #28120

To run an automation, we will:

  1. Fetch (and lock) up to 100 steps.
  2. If no steps are found, enqueue another poll for later, and stop.
  3. Run all the steps.
  4. Possibly enqueue another poll for later.

This patch implements the first of those procedures.

(If you want to see more fully how it will be used, see this PR.)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df763c6a-26f9-44ba-a6b2-acc9ab3c8e92

📥 Commits

Reviewing files that changed from the base of the PR and between fe762b9 and d175693.

📒 Files selected for processing (7)
  • ghost/core/core/server/services/automations/automations-api.ts
  • ghost/core/core/server/services/automations/automations-repository.ts
  • ghost/core/core/server/services/automations/fake-database-automations-repository.ts
  • ghost/core/core/server/services/automations/poll.ts
  • ghost/core/core/server/services/automations/service.js
  • ghost/core/test/unit/server/services/automations/automations-repository.test.ts
  • ghost/core/test/unit/server/services/automations/poll.test.ts
✅ Files skipped from review due to trivial changes (1)
  • ghost/core/core/server/services/automations/service.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • ghost/core/core/server/services/automations/automations-api.ts
  • ghost/core/core/server/services/automations/automations-repository.ts
  • ghost/core/test/unit/server/services/automations/automations-repository.test.ts
  • ghost/core/core/server/services/automations/poll.ts

Walkthrough

This PR introduces a new step-fetching and row-level locking mechanism for the automation execution system. It defines an AutomationStepToRun discriminated union type, extends AutomationsRepository with fetchAndLockSteps(limit), implements the locking and mapping pipeline in the fake-database repository, exposes the method via the automations API, integrates it into the poll flow with batch limiting and rescheduling, and adds unit tests covering locking, limit enforcement, and concurrency.

Possibly related PRs

  • TryGhost/Ghost#28200: Both PRs modify ghost/core/core/server/services/automations/poll.ts’s poll function—main PR wires in automationsApi.fetchAndLockSteps/rescheduling while the retrieved PR adds a NODE_ENV early-return guard.
  • TryGhost/Ghost#28343: Both PRs modify the automations polling orchestration in ghost/core/core/server/services/automations/service.js: the retrieved PR refactors the AutomationsService implementation while this PR wires automationsApi.fetchAndLockSteps into the service-level call.
  • TryGhost/Ghost#28170: Both PRs modify the new automations polling pipeline—poll.ts and the StartAutomationsPollEvent subscription—where this PR extends the polling skeleton with initial fetch/lock and rescheduling logic.

Suggested labels

ok to merge for me

Suggested reviewers

  • cmraible
  • troyciesco
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a fetch and lock steps operation for automations, which is the primary objective of this PR.
Description check ✅ Passed The description is clearly related to the changeset, explaining the context and purpose of the fetch-and-lock operation as the first step in the automation run procedure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fetch-and-lock-automation-steps

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

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

coderabbitai[bot]

This comment was marked as resolved.

towards https://linear.app/ghost/issue/NY-1286
ref #28120

To run an automation, we will:

1. Fetch (and lock) up to 100 steps.
2. If no steps are found, enqueue another poll for later, and stop.
3. Run all the steps.
4. Possibly enqueue another poll for later.

This patch implements the first of those procedures.

(If you want to see more fully how it will be used, see [this PR][0].)

[0]: #28120
@EvanHahn EvanHahn force-pushed the fetch-and-lock-automation-steps branch from fe762b9 to d175693 Compare June 4, 2026 19:33
@EvanHahn EvanHahn marked this pull request as draft June 4, 2026 22:09
@EvanHahn
Copy link
Copy Markdown
Contributor Author

EvanHahn commented Jun 5, 2026

Closing in favor of #28120.

@EvanHahn EvanHahn closed this Jun 5, 2026
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.

1 participant