Skip to content

feat(glue-alpha): overhaul the workflow trigger API - #38579

Open
otaviomacedo wants to merge 2 commits into
mainfrom
otaviom/glue/trigger-action-condition-factories
Open

feat(glue-alpha): overhaul the workflow trigger API#38579
otaviomacedo wants to merge 2 commits into
mainfrom
otaviom/glue/trigger-action-condition-factories

Conversation

@otaviomacedo

@otaviomacedo otaviomacedo commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Reason for this change

Part of the pre-GA API review of @aws-cdk/aws-glue-alpha. Several BLOCKING and RECOMMENDED findings in the Workflow & Triggers area, all touching the same trigger surface that GA will freeze:

  • Action exposed mutually-exclusive job?/crawler? fields policed by a runtime XOR check.
  • Condition exposed optional job?/state?/crawlerName?/crawlState? policed by four runtime throws.
  • IWorkflow omitted two of the six trigger methods (addNotifyEventTrigger, addConditionalTrigger) — they lived on WorkflowBase but not the interface, so fromWorkflow*-imported workflows (typed IWorkflow) could not add event or conditional triggers.
  • Trigger methods returned the raw L1 CfnTrigger (L1 leak).
  • Scheduled triggers were over-fragmented into three hard-coded methods.
  • addNotifyEventTrigger used invented terminology (Glue's type is EVENT).
  • The trigger-option structs chained inheritance to share one field.

Description of changes

Action / Condition → factory subtypes. Abstract classes with factory methods:

  • Action.job(job, options?) / Action.crawler(crawler, options?)
  • Condition.job(job, state, options?) / Condition.crawler(crawler, crawlState, options?)

Choosing job-vs-crawler is now a choice of factory, and the state is a required argument of each condition factory, so "both", "neither", and "target without state" are unrepresentable at compile time. All six ValidationError throws are removed. Jobs are referenced via IJobRef and crawlers via ICrawlerRef (IJob now extends IJobRef via a jobRef accessor on JobBase), so L2 jobs still pass directly while L1 CfnJob/CfnCrawler and imported refs interoperate.

Workflow trigger surface rationalized:

  • IWorkflow now declares every trigger method, so imported workflows have the full capability set.
  • All addXxxTrigger methods return ITriggerRef (generated L1 ref interface) instead of raw CfnTrigger — matches the "secondary-resource factory returns the created resource" guidance without leaking an L1 type.
  • addDaily/Weekly/CustomScheduledTrigger collapse into one addScheduledTrigger({ schedule }), with new TriggerSchedule.daily() / TriggerSchedule.weekly() factories alongside cron()/expression().
  • addNotifyEventTriggeraddEventTrigger; NotifyEventTriggerOptionsEventTriggerOptions.
  • Scheduled/conditional option structs stop chaining and share a minimal StartableTriggerOptions base.

Description of how you validated changes

Full package unit suite (668 passing) updated to the new API, with added coverage for crawler actions/conditions, an overridden condition logical operator, and an imported IWorkflow exercising the previously-omitted trigger methods (compile-time proof they are on the interface). Obsolete runtime-throw tests removed (those states no longer compile). integ.workflow verified via integ-runner --dry-run (no snapshot drift). Package builds clean (jsii compile + lint).

BREAKING CHANGE: trigger Action and Condition are no longer plain objects — use Action.job(...) / Action.crawler(...) and Condition.job(...) / Condition.crawler(...). Jobs are referenced via IJobRef and crawlers via ICrawlerRef (a CfnCrawler instance or CfnCrawler.fromCrawlerName(...)) instead of a CfnCrawler field or crawler-name string; IJob now extends the generated IJobRef. addDailyScheduledTrigger/addWeeklyScheduledTrigger/addCustomScheduledTrigger are replaced by addScheduledTrigger(id, { schedule, ... }) (use TriggerSchedule.daily()/weekly()/cron(...)). addNotifyEventTrigger is renamed addEventTrigger (NotifyEventTriggerOptionsEventTriggerOptions). All addXxxTrigger methods now return ITriggerRef instead of CfnTrigger.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

Trigger Action and Condition were structs whose mutually-exclusive fields were
policed at synth time. Action had optional job/crawler guarded by an XOR check,
and Condition had optional job/state/crawlerName/crawlState guarded by four
separate throws (job-xor-crawler, plus job-requires-state and
crawler-requires-crawlState). Both made illegal states representable.

Turn each into an abstract class with factory methods:

- Action.job(job, options?) / Action.crawler(crawler, options?)
- Condition.job(job, state, options?) / Condition.crawler(crawler, crawlState, options?)

Selecting job-or-crawler is now a choice of factory, and the state is a required
argument of each factory, so "both", "neither", and "target without state" are
all unrepresentable -- the six runtime throws are removed. Each subtype renders
its own CfnTrigger property via an internal method, so the Workflow no longer
branches on which fields are set.

Actions and conditions now reference their job via IJobRef and their crawler via
ICrawlerRef -- the generated L1 ref interfaces -- rather than the L2 IJob and a
raw L1 CfnCrawler. IJob now extends IJobRef (with a jobRef accessor on JobBase),
so this module's L2 jobs are still accepted directly, while L1 CfnJob/CfnCrawler
and imported refs (CfnJob.fromJobName, CfnCrawler.fromCrawlerName) now
interoperate too. Only the resource name is read here, so the richer L2 surface
was never needed.

Addresses the Action and Condition findings from the aws-glue-alpha pre-GA API
review.

BREAKING CHANGE: trigger `Action` and `Condition` are no longer plain objects.
Use `Action.job(job, { ... })` / `Action.crawler(crawler, { ... })` and
`Condition.job(job, state, { ... })` / `Condition.crawler(crawler, crawlState,
{ ... })`. Jobs are referenced via `IJobRef` and crawlers via `ICrawlerRef` (a
`CfnCrawler` instance or `CfnCrawler.fromCrawlerName(...)`) instead of a
`CfnCrawler` field or crawler-name string. `IJob` now extends the generated
`IJobRef`, so third-party `IJob` implementations must expose a `jobRef` accessor.
@github-actions github-actions Bot added the p2 label Aug 17, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 17, 2026 10:38
@otaviomacedo
otaviomacedo marked this pull request as ready for review August 17, 2026 10:39
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This pull request description does not follow the correct template structure.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to follow the PR template and include a line like Closes #123 in the Issue section. If no existing issue matches your change, create one first.

@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label Aug 17, 2026
@mergify
mergify Bot deployed to automation August 17, 2026 10:40 Active
@otaviomacedo otaviomacedo added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Aug 17, 2026
@mergify
mergify Bot deployed to automation August 17, 2026 10:40 Active
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 17, 2026
`IWorkflow` declared only four of the six trigger-adding methods; the other two
(`addNotifyEventTrigger`, `addConditionalTrigger`) lived on `WorkflowBase` but not
the interface, so workflows obtained via `fromWorkflow*` (typed `IWorkflow`) could
not add event or conditional triggers even though the runtime object supports it.
While fixing this, the trigger method surface — which GA will freeze — is
rationalized in one pass:

- `IWorkflow` now declares every trigger method, so imported workflows have the
  full capability set.
- Trigger factory methods return `ITriggerRef` (the generated L1 ref interface)
  instead of the raw L1 `CfnTrigger`, matching the "secondary-resource factory
  returns the created resource" guidance without leaking an L1 type.
- The three fragmented, hard-coded scheduled methods
  (`addDaily/Weekly/CustomScheduledTrigger`) collapse into one
  `addScheduledTrigger({ schedule })`, with `TriggerSchedule.daily()` and
  `TriggerSchedule.weekly()` convenience factories alongside the existing
  `cron()`/`expression()`.
- `addNotifyEventTrigger` is renamed `addEventTrigger` (Glue's type is `EVENT`;
  "Notify" was invented terminology); `NotifyEventTriggerOptions` becomes
  `EventTriggerOptions`.
- The scheduled/conditional option structs stop chaining
  (`ConditionalTriggerOptions extends DailyScheduleTriggerOptions`) and share a
  minimal `StartableTriggerOptions` base instead.

Addresses the Workflow & Triggers findings from the aws-glue-alpha pre-GA API
review (interface omission; L1-leaking return type; scheduled over-fragmentation;
event-trigger naming; option-struct inheritance).

BREAKING CHANGE: `addDailyScheduledTrigger`, `addWeeklyScheduledTrigger`, and
`addCustomScheduledTrigger` are replaced by `addScheduledTrigger(id, { schedule,
... })` — use `TriggerSchedule.daily()` / `TriggerSchedule.weekly()` /
`TriggerSchedule.cron(...)` for the schedule. `addNotifyEventTrigger` is renamed
`addEventTrigger` (and `NotifyEventTriggerOptions` to `EventTriggerOptions`). All
`addXxxTrigger` methods now return `ITriggerRef` instead of `CfnTrigger`.
@otaviomacedo otaviomacedo changed the title feat(glue-alpha): model trigger Action and Condition as factory subtypes feat(glue-alpha): overhaul the workflow trigger API Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants