Skip to content

Started executing automations (in development)#28120

Open
EvanHahn wants to merge 16 commits into
mainfrom
ny-1286-north-star
Open

Started executing automations (in development)#28120
EvanHahn wants to merge 16 commits into
mainfrom
ny-1286-north-star

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented May 25, 2026

closes https://linear.app/ghost/issue/NY-1286
ref #28239
ref #28263
ref #28343
ref #28375
ref #28376

Blocked by #28376.

I recommend reviewing this commit-by-commit.

This change starts executing automations (only in development and test).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

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: dbc5106e-4e2a-4e9f-8a48-e31ff38eb4e7

📥 Commits

Reviewing files that changed from the base of the PR and between b7f0a05 and d46b3ac.

⛔ Files ignored due to path filters (1)
  • ghost/core/test/e2e-api/admin/__snapshots__/automations.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • ghost/core/core/server/services/automations/temporary-fake-database.ts
  • ghost/core/test/e2e-api/members/automations.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • ghost/core/core/server/services/automations/temporary-fake-database.ts
  • ghost/core/test/e2e-api/members/automations.test.js

Walkthrough

This PR implements an automation step polling and execution system: it defines step types and constants, extends the repository API for locking/transition operations, implements those operations in the fake-database repository (locking, finish+enqueue, retry, terminal), provides a poll runner that fetches/locks steps, executes wait and send_email steps with retries and terminal logic, refactors the member-welcome-emails service to send automation emails, wires automationsApi into the service, and adds unit and e2e tests covering these flows.

Possibly related PRs

  • TryGhost/Ghost#28200: Adds environment guard to the poll function entry point
  • TryGhost/Ghost#28263: Adds member_sign_up automation trigger that schedules the StartAutomationsPollEvent executed by this PR's poll implementation
  • TryGhost/Ghost#28343: Extends automations service lifecycle to wire dependencies into the poll handler

Suggested labels

preview

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% 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 clearly summarizes the main change: implementing automation execution in development mode. It directly relates to the primary objective of the PR.
Description check ✅ Passed The description is related to the changeset, providing context about the issue being closed and the scope of the change (execution only in development/test).
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 ny-1286-north-star

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.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 25, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 27059ea

Command Status Duration Result
nx run ghost:build:tsc ❌ Failed 5s View ↗
nx run-many -t lint -p ghost ❌ Failed 11s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 1m 57s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 7m 53s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 3m 3s View ↗
nx run-many -t test:unit -p ghost ✅ Succeeded 31s View ↗
nx run-many --target=build --projects=@tryghost... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-25 21:05:13 UTC

@EvanHahn EvanHahn force-pushed the ny-1286-north-star branch 3 times, most recently from f349d29 to 595810d Compare May 28, 2026 19:23
EvanHahn added a commit that referenced this pull request May 28, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

We can use `export foo` instead of `module.exports`.

This change should have no user impact, but makes an upcoming change
easier.
troyciesco pushed a commit that referenced this pull request Jun 3, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

**I recommend [reviewing this with whitespace changes
disabled](https://github.com/TryGhost/Ghost/pull/28263/changes?w=1).**

When a member signs up, we should trigger an automation run and possibly
insert a new row.

Nothing happens yet when these rows are inserted. That will be done in a
future change.

This is development-only; triggering is a no-op in production.

I tested this by:

- Adding automated tests.

- Verified that the old member welcome email is still sent on member
signup.

- Creating this temporary endpoint and verifying that the results looked
expected after member signup:

  ```js
  router.get('/automations/database-dump', (_req, res) => {
      const db = getTemporaryFakeAutomationsDatabase();
      res.json({
automation_runs: db.prepare('SELECT * FROM automation_runs').all(),
automation_run_steps: db.prepare('SELECT * FROM
automation_run_steps').all()
      });
  });
  ```
EvanHahn added a commit that referenced this pull request Jun 3, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

This change should have no impact on functionality.

We have [a lint rule that limits the length of `index.js` files][0]. In
[an upcoming change][1], the automations service will cross that limit.

This patch moves it into a separate file. Doing so also makes it a
little easier to test.

[0]: https://github.com/TryGhost/eslint-plugin-ghost/blob/22d154a8e3807e4e30219fb8449e7aa9b90a110b/lib/config/node.js#L32-L37
[1]: #28120
EvanHahn added a commit that referenced this pull request Jun 3, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

This change should have no impact on functionality.

We have [a lint rule that limits the length of `index.js` files][0]. In
[an upcoming change][1], the automations service will cross that limit.

This patch moves it into a separate file. Doing so also makes it a
little easier to test.

[0]: https://github.com/TryGhost/eslint-plugin-ghost/blob/22d154a8e3807e4e30219fb8449e7aa9b90a110b/lib/config/node.js#L32-L37
[1]: #28120
EvanHahn added a commit that referenced this pull request Jun 3, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

This change should have no impact on functionality.

We have [a lint rule that limits the length of `index.js` files][0]. In
[an upcoming change][1], the automations service will cross that limit.

This patch moves it into a separate file. Doing so also makes it a
little easier to test.

[0]: https://github.com/TryGhost/eslint-plugin-ghost/blob/22d154a8e3807e4e30219fb8449e7aa9b90a110b/lib/config/node.js#L32-L37
[1]: #28120
EvanHahn added a commit that referenced this pull request Jun 3, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

This change should have no impact on functionality.

We have [a lint rule that limits the length of `index.js` files][0]. In
[an upcoming change][1], the automations service will cross that limit.

This patch moves it into a separate file. Doing so also makes it a
little easier to test.

[0]: https://github.com/TryGhost/eslint-plugin-ghost/blob/22d154a8e3807e4e30219fb8449e7aa9b90a110b/lib/config/node.js#L32-L37
[1]: #28120

(cherry picked from commit 2eb8a65)
EvanHahn added a commit that referenced this pull request 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][0].)

[0]: #28120
@EvanHahn EvanHahn changed the title [DO NOT MERGE] Updated automation execution to use new polling logic Started executing automations (in development) Jun 4, 2026
EvanHahn added a commit that referenced this pull request Jun 4, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

This is a test-only change that just makes things a little easier to
read. I think it's useful on its own, but it'll also be useful for [an
upcoming change](#28120).
EvanHahn added a commit that referenced this pull request Jun 4, 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][0].)

[0]: #28120
EvanHahn added a commit that referenced this pull request Jun 4, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

*I recommend reviewing this with whitespace changes disabled.*

**What:** We want to trigger automations after members are inserted.

**Why:** If we don't do this, automations could run before the member
exists in the database.
EvanHahn added a commit that referenced this pull request Jun 4, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

*I recommend reviewing this with whitespace changes disabled.*

**What:** We want to trigger automations after members are inserted.

**Why:** If we don't do this, automations could run before the member
exists in the database.
EvanHahn added a commit that referenced this pull request Jun 5, 2026
towards https://linear.app/ghost/issue/NY-1286
ref #28120

*I recommend reviewing this with whitespace changes disabled.*

**What:** We want to trigger automations after members are inserted.

**Why:** If we don't do this, automations could run before the member
exists in the database.

(cherry picked from commit e04da95)
@EvanHahn EvanHahn force-pushed the ny-1286-north-star branch from cbc2db3 to 8b0cf45 Compare June 5, 2026 17:23
EvanHahn added 5 commits June 5, 2026 14:02
towards https://linear.app/ghost/issue/NY-1286
ref #28120

*I recommend reviewing this with whitespace changes disabled.*

**What:** We want to trigger automations after members are inserted.

**Why:** If we don't do this, automations could run before the member
exists in the database.

(cherry picked from commit e04da95)
These functions are neither called nor implemented! But their skeletons
are now here, along with some documentation about what they'll do.
@EvanHahn EvanHahn force-pushed the ny-1286-north-star branch from 8b0cf45 to b7f0a05 Compare June 5, 2026 20:18
@EvanHahn EvanHahn marked this pull request as ready for review June 5, 2026 20:21
@EvanHahn EvanHahn force-pushed the ny-1286-north-star branch from b7f0a05 to d46b3ac Compare June 5, 2026 20:25
@EvanHahn EvanHahn requested a review from troyciesco June 5, 2026 20:56
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