Skip to content

Started executing automations (in development)#28120

Merged
EvanHahn merged 20 commits into
mainfrom
ny-1286-north-star
Jun 8, 2026
Merged

Started executing automations (in development)#28120
EvanHahn merged 20 commits into
mainfrom
ny-1286-north-star

Conversation

@EvanHahn

@EvanHahn EvanHahn commented May 25, 2026

Copy link
Copy Markdown
Contributor

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

I recommend reviewing this commit-by-commit.

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

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

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: c306894d-1986-4f1d-9ef5-3c2a9d95a8f7

📥 Commits

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

⛔ 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 (12)
  • ghost/core/core/server/services/automations/automations-api.ts
  • ghost/core/core/server/services/automations/automations-repository.ts
  • ghost/core/core/server/services/automations/constants.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/core/server/services/automations/temporary-fake-database.ts
  • ghost/core/core/server/services/member-welcome-emails/service.js
  • ghost/core/core/server/services/members/members-api/repositories/member-repository.js
  • ghost/core/test/e2e-api/members/automations.test.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/constants.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • ghost/core/core/server/services/automations/automations-api.ts
  • ghost/core/core/server/services/automations/service.js
  • ghost/core/core/server/services/automations/poll.ts
  • ghost/core/core/server/services/members/members-api/repositories/member-repository.js
  • ghost/core/core/server/services/member-welcome-emails/service.js
  • ghost/core/test/e2e-api/members/automations.test.js
  • ghost/core/core/server/services/automations/temporary-fake-database.ts
  • ghost/core/core/server/services/automations/automations-repository.ts
  • ghost/core/test/unit/server/services/automations/poll.test.ts
  • ghost/core/test/unit/server/services/automations/automations-repository.test.ts
  • ghost/core/core/server/services/automations/fake-database-automations-repository.ts

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: Both PRs change ghost/core/core/server/services/automations/poll.ts’s poll function—one adds a NODE_ENV early-return guard while this PR rewrites/extends the polling logic to fetch/lock and execute automation steps.
  • TryGhost/Ghost#28170: Adds a skeleton poll implementation and wiring that this PR expands into a full fetch/lock/execute flow.
  • TryGhost/Ghost#27909: Also modifies automations polling and enqueue scheduling behavior related to this PR's poll/enqueue logic.

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 and concisely describes the main objective of the changeset—starting automation execution in development environments.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose (executing automations in dev/test), referencing related issues, and noting the author recommends reviewing commit-by-commit.
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

nx-cloud Bot commented May 25, 2026

Copy link
Copy Markdown

🤖 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 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 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
@EvanHahn EvanHahn force-pushed the ny-1286-north-star branch from d46b3ac to 183d864 Compare June 7, 2026 18:37
troyciesco pushed a commit that referenced this pull request Jun 8, 2026
…8376)

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

*I recommend [reviewing this with whitespace changes disabled][0].*

**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.

[0]: https://github.com/TryGhost/Ghost/pull/28376/changes?w=1
Comment thread ghost/core/test/unit/server/services/automations/poll.test.ts Outdated

Copilot AI 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.

Pull request overview

This PR starts executing member welcome-email automations by implementing a polling/execution loop (dev + test environments only), including step locking/retries, and wiring the poller into the automations service. It also extends the fake automations database/schema to include sender fields and adds unit/e2e coverage for step execution.

Changes:

  • Implemented automations step polling/execution with locking, retry, and terminal status handling.
  • Extended the fake automations repository + temporary schema to support fetching/locking/running steps (including sender metadata).
  • Added unit + e2e tests (and updated snapshots) validating step locking, progression, and email sending.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ghost/core/core/server/services/automations/poll.ts Implements the poll loop that fetches/locks steps, executes them, retries/fails, and schedules the next poll.
ghost/core/core/server/services/automations/fake-database-automations-repository.ts Adds step locking/fetching and step lifecycle operations (finish/terminal/retry) to the fake repository.
ghost/core/core/server/services/automations/automations-repository.ts Introduces step-to-run and terminal-status types + repository methods for polling/execution.
ghost/core/core/server/services/automations/constants.ts Defines shared constants for locking, attempt limits, batching, and retry delays.
ghost/core/core/server/services/automations/automations-api.ts Exposes new repository operations (fetch/lock/finish/terminal/retry) via the automations API layer.
ghost/core/core/server/services/automations/service.js Wires poll() into the service by injecting automationsApi + memberWelcomeEmailService.
ghost/core/core/server/services/automations/temporary-fake-database.ts Updates fake automations schema + seed data to include sender fields for email actions.
ghost/core/core/server/services/member-welcome-emails/service.js Refactors sending to allow automation-driven email sends (including sender fields + design setting lookup).
ghost/core/test/unit/server/services/automations/poll.test.ts Adds unit coverage for poll behavior (env gating, batching, retrying, terminal statuses, scheduling).
ghost/core/test/unit/server/services/automations/automations-repository.test.ts Adds unit tests for step locking and lifecycle operations in the repository.
ghost/core/test/e2e-api/members/automations.test.js Adds e2e test to run the full free-member automation and assert resulting outgoing emails.
ghost/core/test/e2e-api/admin/snapshots/automations.test.js.snap Updates snapshots to reflect sender fields coming from automation action revisions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ghost/core/core/server/services/automations/poll.ts
Comment thread ghost/core/core/server/services/automations/poll.ts
@EvanHahn EvanHahn added the ok to merge for me You can merge this on my behalf if you want. label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok to merge for me You can merge this on my behalf if you want.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants