Module: Lev::Routine::ClassMethods
- Defined in:
- lib/lev/routine.rb
Instance Method Summary collapse
- #[](*args, **kwargs, &block) ⇒ Object
- #active_job_enqueue_options ⇒ Object
- #call(*args, **kwargs, &block) ⇒ Object
- #class_to_symbol(klass) ⇒ Object
- #create_status ⇒ Object
- #delegates_to ⇒ Object
- #express_output ⇒ Object
- #find_status(id) ⇒ Object
- #job_class ⇒ Object
- #nested_routines ⇒ Object
- #perform_later(*args, **kwargs, &block) ⇒ Object
- #raise_fatal_errors? ⇒ Boolean
- #set(options) ⇒ Object
- #transaction_isolation ⇒ Object
-
#uses_routine(routine_class, options = {}) ⇒ Object
Called at a routine’s class level to foretell which other routines will be used when this routine executes.
Instance Method Details
#[](*args, **kwargs, &block) ⇒ Object
207 208 209 210 211 |
# File 'lib/lev/routine.rb', line 207 def [](*args, **kwargs, &block) result = call(*args, **kwargs, &block) result.errors.raise_exception_if_any! result.outputs.send(@express_output) end |
#active_job_enqueue_options ⇒ Object
221 222 223 |
# File 'lib/lev/routine.rb', line 221 def @active_job_enqueue_options || { queue: :default } end |
#call(*args, **kwargs, &block) ⇒ Object
203 204 205 |
# File 'lib/lev/routine.rb', line 203 def call(*args, **kwargs, &block) new.call(*args, **kwargs, &block) end |
#class_to_symbol(klass) ⇒ Object
267 268 269 |
# File 'lib/lev/routine.rb', line 267 def class_to_symbol(klass) klass.name.underscore.gsub('/','_').to_sym end |
#create_status ⇒ Object
271 272 273 |
# File 'lib/lev/routine.rb', line 271 def create_status create_status_proc.call end |
#delegates_to ⇒ Object
254 255 256 |
# File 'lib/lev/routine.rb', line 254 def delegates_to @delegates_to end |
#express_output ⇒ Object
250 251 252 |
# File 'lib/lev/routine.rb', line 250 def express_output @express_output end |
#find_status(id) ⇒ Object
275 276 277 |
# File 'lib/lev/routine.rb', line 275 def find_status(id) find_status_proc.call(id) end |
#job_class ⇒ Object
217 218 219 |
# File 'lib/lev/routine.rb', line 217 def job_class @job_class || Lev::ActiveJob::Base end |
#nested_routines ⇒ Object
258 259 260 |
# File 'lib/lev/routine.rb', line 258 def nested_routines @nested_routines ||= {} end |
#perform_later(*args, **kwargs, &block) ⇒ Object
225 226 227 228 |
# File 'lib/lev/routine.rb', line 225 def perform_later(*args, **kwargs, &block) # Delegate to a subclass of Lev::Routine::ActiveJob::Base job_class.new.perform_later(self, , *args, **kwargs, &block) end |
#raise_fatal_errors? ⇒ Boolean
262 263 264 265 |
# File 'lib/lev/routine.rb', line 262 def raise_fatal_errors? @raise_fatal_errors || (Lev.configuration.raise_fatal_errors && @raise_fatal_errors.nil?) end |
#set(options) ⇒ Object
213 214 215 |
# File 'lib/lev/routine.rb', line 213 def set() Lev::ActiveJob::ConfiguredJob.new(self, ) end |
#transaction_isolation ⇒ Object
246 247 248 |
# File 'lib/lev/routine.rb', line 246 def transaction_isolation @transaction_isolation ||= TransactionIsolation.mysql_default end |
#uses_routine(routine_class, options = {}) ⇒ Object
Called at a routine’s class level to foretell which other routines will be used when this routine executes. Helpful for figuring out ahead of time what kind of transaction isolation level should be used.
233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/lev/routine.rb', line 233 def uses_routine(routine_class, ={}) symbol = [:as] || class_to_symbol(routine_class) warn("Routine #{routine_class} has already been registered") if nested_routines[symbol] nested_routines[symbol] = { routine_class: routine_class, options: } transaction_isolation.replace_if_more_isolated(routine_class.transaction_isolation) end |