-
Notifications
You must be signed in to change notification settings - Fork 0
Add workflow DSL, triggers, validators, and scheduling #1
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| up: | ||
| rails s | ||
|
|
||
| workflows-run: | ||
| rails r3x:workflows:run | ||
|
|
||
| workflows-list: | ||
| rails r3x:workflows:list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/lib/r3x/triggers/rss.rb → app/lib/r3x/services/rss_parser.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,26 @@ | ||
| development: | ||
| porto_santo_news: | ||
| class: R3x::RunWorkflowJob | ||
| args: [porto_santo_news] | ||
| schedule: "*/15 * * * *" | ||
| queue: default | ||
| <% require "fugit" %> | ||
| <% | ||
| # Static maintenance tasks (always present) | ||
| static_tasks = { | ||
| "clear_solid_queue_finished_jobs" => { | ||
| "command" => "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)", | ||
| "schedule" => "every hour at minute 12", | ||
| "queue" => "default" | ||
| } | ||
| } | ||
|
|
||
| production: | ||
| porto_santo_news: | ||
| class: R3x::RunWorkflowJob | ||
| args: [porto_santo_news] | ||
| schedule: "*/15 * * * *" | ||
| queue: default | ||
| # Load workflows and generate recurring tasks from DSL | ||
| R3x::WorkflowPackLoader.load! | ||
| dynamic_tasks = R3x::RecurringTasksConfig.to_h | ||
|
|
||
| clear_solid_queue_finished_jobs: | ||
| command: "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)" | ||
| schedule: every hour at minute 12 | ||
| # Merge static and dynamic tasks | ||
| all_tasks = static_tasks.merge(dynamic_tasks) | ||
|
|
||
| # Generate for all environments | ||
| config = { | ||
| "development" => all_tasks, | ||
| "production" => all_tasks, | ||
| "test" => {} # No recurring tasks in test | ||
| } | ||
| %> | ||
| <%= config.to_yaml %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| Rails.application.routes.draw do | ||
| # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html | ||
| # Mount Mission Control Jobs dashboard | ||
| mount MissionControl::Jobs::Engine, at: "/jobs" | ||
|
|
||
| # Root redirects to Mission Control Jobs dashboard (using unnamed route to hide from Mission Control) | ||
| get "/", to: redirect("/jobs") | ||
|
|
||
| # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. | ||
| # Can be used by load balancers and uptime monitors to verify that the app is live. | ||
| get "up" => "rails/health#show", as: :rails_health_check | ||
|
|
||
| # Defines the root path route ("/") | ||
| # root "posts#index" | ||
| get "up" => "rails/health#show", :as => :rails_health_check | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module R3x | ||
| class RecurringTasksConfig | ||
| class << self | ||
| def to_h | ||
| result = {} | ||
|
|
||
| WorkflowRegistry.all.each do |workflow_class| | ||
| schedule = workflow_class.schedule_trigger | ||
| next unless schedule | ||
|
|
||
| workflow_key = workflow_class.workflow_key | ||
|
|
||
| result[workflow_key] = { | ||
| "class" => "R3x::RunWorkflowJob", | ||
| "args" => [ workflow_key, { "triggered_by" => "schedule" } ], | ||
| "schedule" => schedule.cron, | ||
| "queue" => "default" | ||
| } | ||
| end | ||
|
|
||
| result | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| module R3x | ||
| class TriggeredBy | ||
| attr_reader :type | ||
|
|
||
| def initialize(type) | ||
| @type = type.to_sym | ||
| end | ||
|
|
||
| def schedule? | ||
| type == :schedule | ||
| end | ||
|
|
||
| def rss? | ||
| type == :rss | ||
| end | ||
|
|
||
| def manual? | ||
| type == :manual | ||
| end | ||
|
|
||
| def ==(other) | ||
| return type == other if other.is_a?(Symbol) | ||
| return type == other.type if other.is_a?(TriggeredBy) | ||
| false | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| module R3x | ||
| module Triggers | ||
| class << self | ||
| def supported_types | ||
| trigger_files.filter_map do |file| | ||
| basename = File.basename(file, ".rb") | ||
| next if basename == "base" | ||
| basename.to_sym | ||
| end.sort | ||
| end | ||
|
|
||
| def resolve(type) | ||
| type_sym = type.to_sym | ||
| supported = supported_types | ||
|
|
||
| unless supported.include?(type_sym) | ||
| raise ArgumentError, "Unknown trigger type: #{type}. No file found for trigger '#{type_sym}.rb' in #{triggers_dir}. " \ | ||
| "Supported types: #{supported.map { |t| ":#{t}" }.join(", ")}" | ||
| end | ||
|
|
||
| class_name = type.to_s.camelize | ||
| full_class_name = "::R3x::Triggers::#{class_name}" | ||
|
|
||
| begin | ||
| full_class_name.constantize | ||
| rescue NameError | ||
| raise ArgumentError, "Trigger file '#{type_sym}.rb' exists but class #{full_class_name} is not defined or failed to load." | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def triggers_dir | ||
| File.expand_path("triggers", __dir__) | ||
| end | ||
|
|
||
| def trigger_files | ||
| Dir.glob(File.join(triggers_dir, "*.rb")) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| module R3x | ||
| module Triggers | ||
| class Base | ||
| attr_reader :type, :options | ||
|
|
||
| def initialize(type, **options) | ||
| @type = type | ||
| @options = options | ||
| end | ||
|
|
||
| def validate! | ||
| raise NotImplementedError, "#{self.class.name} must implement validate!" | ||
| end | ||
|
|
||
| def to_h | ||
| { type: type }.merge(options) | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_hcurrently gates every workflow onschedule_triggerand skips it otherwise, so workflows configured withtrigger :rssnever get a recurring task entry at all. In this commit,rss_triggersis defined and validated but not consumed by any scheduler path, so RSS-triggered workflows will not execute automatically in production despite being accepted by the DSL.Useful? React with 👍 / 👎.