Class: PUNK::Worker

Inherits:
Runnable show all
Includes:
Sidekiq::Worker
Defined in:
lib/punk/framework/worker.rb

Instance Attribute Summary

Attributes included from Validatable

#errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runnable

args, #method_missing, #respond_to_missing?

Methods included from Validatable

#default_validation_helpers_options, #get_column_value, #valid?, #validate, #validates_not_empty

Methods included from Plugins::Validation::InstanceMethods

#validates_email, #validates_event, #validates_parse_id, #validates_phone, #validates_state, #validates_subdomain, #validates_url

Methods inherited from Settings

#method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PUNK::Runnable

Class Method Details

.perform_now(**kwargs) ⇒ Object



9
10
11
12
13
# File 'lib/punk/framework/worker.rb', line 9

def self.perform_now(**kwargs)
  worker = new
  worker.define_singleton_method :logger, -> { SemanticLogger['PUNK::SKQ'] }
  worker.send(:perform, **kwargs)
end

Instance Method Details

#perform(kwargs = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/punk/framework/worker.rb', line 15

def perform(kwargs={})
  @_started = Time.now.utc
  logger.info "Started #{self.class.name}", kwargs.sanitize.inspect
  logger.push_tags(self.class.name)
  _init_runnable(kwargs.deep_symbolize_keys)
  raise BadRequest, "validation failed" unless valid?
  process
  nil
rescue BadRequest => e
  logger.error e.message
  logger.error errors.full_messages.to_sentence
  raise
ensure
  duration = 1000.0 * (Time.now.utc - @_started)
  logger.pop_tags
  logger.info message: "Completed #{self.class.name}", duration: duration
  SemanticLogger.flush
end