Module: DurableFlow
- Defined in:
- lib/durable_flow.rb,
lib/durable_flow/live.rb,
lib/durable_flow/engine.rb,
lib/durable_flow/errors.rb,
lib/durable_flow/schema.rb,
lib/durable_flow/railtie.rb,
lib/durable_flow/version.rb,
lib/durable_flow/workflow.rb,
lib/durable_flow/dispatcher.rb,
lib/durable_flow/serializer.rb,
lib/durable_flow/step_proxy.rb,
lib/durable_flow/test_helper.rb,
lib/durable_flow/workflow_logger.rb,
lib/durable_flow/event_subscriber.rb,
lib/durable_flow/workflow_timeline.rb,
lib/durable_flow/models/workflow_log.rb,
lib/durable_flow/models/workflow_run.rb,
lib/durable_flow/models/workflow_step.rb,
lib/durable_flow/models/workflow_wait.rb,
lib/durable_flow/models/workflow_event.rb,
lib/durable_flow/models/application_record.rb,
lib/generators/durable_flow/install_generator.rb,
app/controllers/durable_flow/workflow_runs_controller.rb
Defined Under Namespace
Modules: Generators, Live, Schema, Serializer, TestHelper
Classes: ApplicationRecord, Dispatcher, Engine, Error, EventSubscriber, Interrupt, MissingStepResultError, Pause, Railtie, StepProxy, WaitTimeoutError, Workflow, WorkflowEvent, WorkflowLog, WorkflowLogger, WorkflowRun, WorkflowRunsController, WorkflowStep, WorkflowTimeline, WorkflowWait
Constant Summary
collapse
- NOOP_LIVE_BROADCASTER =
->(_change) {}
- WORKFLOW_COMPLETED_EVENT =
"durable_flow.workflow.completed"
- WORKFLOW_FAILED_EVENT =
"durable_flow.workflow.failed"
- IGNORED_EVENT_NAMESPACES =
%w[
action_controller
action_mailbox
action_mailer
action_text
action_view
active_job
active_record
active_storage
active_support
rails
].freeze
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.broadcast_change(change) ⇒ Object
88
89
90
91
92
|
# File 'lib/durable_flow.rb', line 88
def broadcast_change(change)
broadcast_live_change(live_broadcaster, change)
live_subscribers.each { |subscriber| broadcast_live_change(subscriber, change) }
change
end
|
.database_ready? ⇒ Boolean
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/durable_flow.rb', line 110
def database_ready?
return false unless defined?(ActiveRecord::Base)
return false unless ActiveRecord::Base.connected?
connection = ActiveRecord::Base.connection
%w[
durable_flow_workflow_runs
durable_flow_workflow_steps
durable_flow_workflow_events
durable_flow_workflow_waits
durable_flow_workflow_logs
].all? { |table| connection.data_source_exists?(table) }
rescue ActiveRecord::ActiveRecordError
false
end
|
.notify(name, payload = nil, **kwargs) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/durable_flow.rb', line 73
def notify(name, payload = nil, **kwargs)
if defined?(Rails) && Rails.respond_to?(:event)
payload ? Rails.event.notify(name, payload, **kwargs) : Rails.event.notify(name, **kwargs)
else
event = {
name: name.to_s,
payload: payload || kwargs,
tags: {},
context: {},
timestamp: Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond),
}
EventSubscriber.new.emit(event)
end
end
|
.on_change(&block) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/durable_flow.rb', line 94
def on_change(&block)
raise ArgumentError, "Provide a block" unless block
self.live_subscribers += [ block ]
block
end
|
.record_event?(name) ⇒ Boolean
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/durable_flow.rb', line 126
def record_event?(name)
return false if Fiber[:durable_flow_recording_event]
name = name.to_s
return true if name.start_with?("durable_flow.")
IGNORED_EVENT_NAMESPACES.none? do |namespace|
name == namespace || name.start_with?("#{namespace}.") || name.end_with?(".#{namespace}")
end
end
|
.reset_live_broadcasters! ⇒ Object
105
106
107
108
|
# File 'lib/durable_flow.rb', line 105
def reset_live_broadcasters!
self.live_broadcaster = NOOP_LIVE_BROADCASTER
self.live_subscribers = []
end
|
.subscribe_to_rails_events! ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/durable_flow.rb', line 56
def subscribe_to_rails_events!
return event_subscriber if event_subscriber
return unless defined?(Rails) && Rails.respond_to?(:event)
self.event_subscriber = EventSubscriber.new
Rails.event.subscribe(event_subscriber) { |event| record_event?(event[:name]) }
event_subscriber
end
|
.unsubscribe_from_changes(subscriber) ⇒ Object
101
102
103
|
# File 'lib/durable_flow.rb', line 101
def unsubscribe_from_changes(subscriber)
self.live_subscribers -= [ subscriber ]
end
|
.unsubscribe_from_rails_events! ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/durable_flow.rb', line 65
def unsubscribe_from_rails_events!
return unless event_subscriber
return unless defined?(Rails) && Rails.respond_to?(:event)
Rails.event.unsubscribe(event_subscriber)
self.event_subscriber = nil
end
|