Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further automation builder refactoring. #15500

Merged
merged 8 commits into from
Feb 6, 2025
Merged

Further automation builder refactoring. #15500

merged 8 commits into from
Feb 6, 2025

Conversation

samwho
Copy link
Collaborator

@samwho samwho commented Feb 6, 2025

Description

While working on a previous automation builder refactor I noticed that all of the trigger methods (e.g. appAction, rowCreated, etc.) took both an inputs and an outputs. The outputs were optional and only get used later if/when you call run. This confused me and made it difficult to follow the flow of information.

I've refactored this flow so that this:

await createAutomationBuilder(config)
  .cron({ cron: "* * * * *" }, { timestamp: 123456789 })
  .serverLog({ text: "Hello!" })
  .run()

Becomes this:

await createAutomationBuilder(config)
  .onCron({ cron: "* * * * *" })
  .serverLog({ text: "Hello!" })
  .test({ timestamp: 123456789 })

A few things are happening here:

  1. Triggers have been renamed to start with on to make them read nicer in-situ (onCron is admittedly not the nicest example of this, things like onRowSaved is much nicer though).
  2. createAutomationBuilder now returns a TriggerBuilder that you can only use to choose a trigger. Once you do, a StepBuilder<T> is returned that lets you create steps. This forces you to choose exactly 1 trigger, and types the automation based on the trigger chosen. This T is then used later in the renamed test (used to be run but test makes it more clear what API is being used) to know what output type to accept.
  3. Not shown but the save method (which test calls internally) now returns an AutomationRunner<T> which allows you to call test as many times as you want without creating a new automation. This opens up some new use-cases of testing an automation multiple times without having to do gymnastic with the builder API.

So in short this new structure makes it more difficult to make mistakes, and more obvious what data is going where and when.

Copy link

qa-wolf bot commented Feb 6, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@github-actions github-actions bot added firestorm Data/Infra/Revenue Team size/m labels Feb 6, 2025
@samwho samwho requested a review from PClmnt February 6, 2025 16:20
@samwho samwho marked this pull request as ready for review February 6, 2025 16:20
@samwho samwho requested a review from a team as a code owner February 6, 2025 16:20
@samwho samwho requested review from mike12345567 and removed request for a team February 6, 2025 16:20
@github-actions github-actions bot added size/l and removed size/m labels Feb 6, 2025
Copy link
Collaborator

@mike12345567 mike12345567 left a comment

Choose a reason for hiding this comment

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

LGTM - very nice!

@samwho samwho merged commit 72728e6 into master Feb 6, 2025
20 checks passed
@samwho samwho deleted the automation-tests-5 branch February 6, 2025 17:19
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
firestorm Data/Infra/Revenue Team size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants