Skip to content

Add change-detection and trigger registry - #8

Merged
zewelor merged 4 commits into
mainfrom
work_on_triggers
Mar 20, 2026
Merged

Add change-detection and trigger registry#8
zewelor merged 4 commits into
mainfrom
work_on_triggers

Conversation

@zewelor

@zewelor zewelor commented Mar 19, 2026

Copy link
Copy Markdown
Contributor
  • Add ChangeDetectionJob and TriggerState model with migration
  • Introduce TriggerCollection and stable trigger unique_key values
  • Add ChangeDetecting concern for detector triggers and scheduler support
  • Have RecurringTasksConfig schedule ChangeDetectionJob for detectors
  • Make RunWorkflowJob accept trigger_key and payload; pass payload to workflow
  • Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem

- Add ChangeDetectionJob and TriggerState model with migration
- Introduce TriggerCollection and stable trigger `unique_key` values
- Add ChangeDetecting concern for detector triggers and scheduler support
- Have RecurringTasksConfig schedule ChangeDetectionJob for detectors
- Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow
- Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46d1d430a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/lib/r3x/client/http.rb
Comment thread app/jobs/r3x/change_detection_job.rb Outdated
Comment thread lib/r3x/recurring_tasks_config.rb

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds a change-detection pipeline for workflows by introducing change-detecting triggers, persistent per-trigger state, and a registry keyed by stable unique_key values so schedulers/jobs can reliably resolve triggers and pass runtime payloads into workflow execution.

Changes:

  • Added ChangeDetectionJob + TriggerState model/migration to persist detector state and enqueue runs only on detected changes.
  • Introduced TriggerCollection and per-trigger unique_key for trigger de-duplication and lookup, updating scheduling to key tasks by workflow_key + trigger_key.
  • Updated RunWorkflowJob/execution context to accept trigger_key and a runtime payload, and added supporting tests + a fake change-detecting trigger.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/support/fake_change_detecting_trigger.rb Adds a test-only change-detecting trigger with stable identity-based unique_key.
test/lib/r3x/workflow_test.rb Extends trigger validation tests and adds coverage for duplicate trigger keys and key stability.
test/lib/r3x/workflow_context_test.rb Adds coverage for exposing runtime payload via trigger execution.
test/lib/r3x/recurring_tasks_config_test.rb Updates recurring-task expectations for trigger-keyed tasks and adds change-detection scheduling coverage.
test/jobs/r3x/run_workflow_job_test.rb Updates RunWorkflowJob tests for trigger_key lookup and payload pass-through.
test/jobs/r3x/change_detection_job_test.rb Adds end-to-end tests for change detection, state persistence, enqueueing, and error recording.
lib/r3x/workflow.rb Replaces array trigger storage with TriggerCollection and adds triggers_by_key.
lib/r3x/triggers/concerns/change_detecting.rb Adds ChangeDetecting concern contract (change_detecting?, detect_changes).
lib/r3x/triggers/base.rb Adds default change_detecting?/cron_schedulable? and a hashed unique_key.
lib/r3x/trigger_execution.rb Adds payload to runtime trigger execution object.
lib/r3x/trigger_collection.rb New collection enforcing unique trigger keys and providing lookup by key.
lib/r3x/recurring_tasks_config.rb Generates Solid Queue recurring tasks keyed by workflow_key:trigger_key, scheduling detection job for detectors.
db/schema.rb Adds trigger_states table schema.
db/migrate/20260318100000_create_trigger_states.rb Migration creating trigger_states with indexes.
app/models/r3x/trigger_state.rb Adds model validations and helpers to record checks/errors.
app/lib/r3x/client/http.rb Changes get return value and adds post.
app/jobs/r3x/run_workflow_job.rb Switches to trigger lookup by trigger_key and passes runtime payload into context.
app/jobs/r3x/change_detection_job.rb New job to evaluate detector triggers, update TriggerState, and enqueue workflow runs on changes.
Gemfile / Gemfile.lock Adds pg and bumps loofah.
AGENTS.md Updates codebase map and control-flow formatting; documents change-detection components.

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

Comment thread lib/r3x/recurring_tasks_config.rb
Comment thread app/lib/r3x/client/http.rb
Comment thread app/models/r3x/trigger_state.rb Outdated
Comment thread lib/r3x/triggers/base.rb
zewelor and others added 3 commits March 19, 2026 21:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Remove fetch_body, discord_output, and http_client methods.
- Change made in `lib/r3x/workflow_context.rb`.
- Reduce hidden dependencies and side effects in the context.
- Encourage injection of HTTP clients/outputs for testability.
- Make trigger state update and job enqueue atomic in ChangeDetectionJob
- Add argument normalization to RunWorkflowJob and ChangeDetectionJob
- Add test that simulates enqueue failure and preserves trigger state
- Adjust test payload expectation to use symbolized keys
- Update AGENTS.md to document Solid Queue transactional behavior
@zewelor
zewelor merged commit 5a8a2a2 into main Mar 20, 2026
3 checks passed
@zewelor
zewelor deleted the work_on_triggers branch March 20, 2026 07:39
zewelor added a commit that referenced this pull request Mar 20, 2026
* Add change-detection and trigger registry

- Add ChangeDetectionJob and TriggerState model with migration
- Introduce TriggerCollection and stable trigger `unique_key` values
- Add ChangeDetecting concern for detector triggers and scheduler support
- Have RecurringTasksConfig schedule ChangeDetectionJob for detectors
- Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow
- Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem

* Update app/models/r3x/trigger_state.rb

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove HTTP/Discord helpers from WorkflowContext

- Remove fetch_body, discord_output, and http_client methods.
- Change made in `lib/r3x/workflow_context.rb`.
- Reduce hidden dependencies and side effects in the context.
- Encourage injection of HTTP clients/outputs for testability.

* Make enqueueing atomic for change detection

- Make trigger state update and job enqueue atomic in ChangeDetectionJob
- Add argument normalization to RunWorkflowJob and ChangeDetectionJob
- Add test that simulates enqueue failure and preserves trigger state
- Adjust test payload expectation to use symbolized keys
- Update AGENTS.md to document Solid Queue transactional behavior

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
zewelor added a commit that referenced this pull request Mar 20, 2026
* Add change-detection and trigger registry

- Add ChangeDetectionJob and TriggerState model with migration
- Introduce TriggerCollection and stable trigger `unique_key` values
- Add ChangeDetecting concern for detector triggers and scheduler support
- Have RecurringTasksConfig schedule ChangeDetectionJob for detectors
- Make RunWorkflowJob accept `trigger_key` and payload; pass payload to workflow
- Add tests and fake trigger; update schema, docs, HTTP client, and add pg gem

* Update app/models/r3x/trigger_state.rb



* Remove HTTP/Discord helpers from WorkflowContext

- Remove fetch_body, discord_output, and http_client methods.
- Change made in `lib/r3x/workflow_context.rb`.
- Reduce hidden dependencies and side effects in the context.
- Encourage injection of HTTP clients/outputs for testability.

* Make enqueueing atomic for change detection

- Make trigger state update and job enqueue atomic in ChangeDetectionJob
- Add argument normalization to RunWorkflowJob and ChangeDetectionJob
- Add test that simulates enqueue failure and preserves trigger state
- Adjust test payload expectation to use symbolized keys
- Update AGENTS.md to document Solid Queue transactional behavior

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants