Module: Lev::Routine::ClassMethods

Defined in:
lib/lev/routine.rb

Instance Method Summary collapse

Instance Method Details

#[](*args, &block) ⇒ Object



205
206
207
208
209
# File 'lib/lev/routine.rb', line 205

def [](*args, &block)
  result = call(*args, &block)
  result.errors.raise_exception_if_any!
  result.outputs.send(@express_output)
end

#active_job_enqueue_optionsObject



220
221
222
# File 'lib/lev/routine.rb', line 220

def active_job_enqueue_options
  @active_job_enqueue_options || { queue: :default }
end

#call(*args, &block) ⇒ Object



201
202
203
# File 'lib/lev/routine.rb', line 201

def call(*args, &block)
  new.call(*args, &block)
end

#class_to_symbol(klass) ⇒ Object



262
263
264
# File 'lib/lev/routine.rb', line 262

def class_to_symbol(klass)
  klass.name.underscore.gsub('/','_').to_sym
end

#delegates_toObject



249
250
251
# File 'lib/lev/routine.rb', line 249

def delegates_to
  @delegates_to
end

#express_outputObject



245
246
247
# File 'lib/lev/routine.rb', line 245

def express_output
  @express_output
end

#nested_routinesObject



253
254
255
# File 'lib/lev/routine.rb', line 253

def nested_routines
  @nested_routines ||= {}
end

#perform_later(*args, &block) ⇒ Object



215
216
217
218
# File 'lib/lev/routine.rb', line 215

def perform_later(*args, &block)
  # Delegate to a subclass of Lev::Routine::ActiveJob::Base
  Lev::ActiveJob::Base.new.perform_later(self, active_job_enqueue_options, *args, &block)
end

#raise_fatal_errors?Boolean



257
258
259
260
# File 'lib/lev/routine.rb', line 257

def raise_fatal_errors?
  @raise_fatal_errors ||
    (Lev.configuration.raise_fatal_errors && @raise_fatal_errors.nil?)
end

#set(options) ⇒ Object



211
212
213
# File 'lib/lev/routine.rb', line 211

def set(options)
  Lev::ActiveJob::ConfiguredJob.new(self, options)
end

#transaction_isolationObject



241
242
243
# File 'lib/lev/routine.rb', line 241

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.

Raises:

  • (Lev.configuration.illegal_argument_error)


227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/lev/routine.rb', line 227

def uses_routine(routine_class, options={})
  symbol = options[:as] || class_to_symbol(routine_class)

  raise Lev.configuration.illegal_argument_error, "Routine #{routine_class} has already been registered" \
    if nested_routines[symbol]

  nested_routines[symbol] = {
    routine_class: routine_class,
    options: options
  }

  transaction_isolation.replace_if_more_isolated(routine_class.transaction_isolation)
end