Class: Flake

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/flakes.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute(args = {}) ⇒ Object



13
14
15
# File 'lib/flakes.rb', line 13

def self.execute(args = {})
  new(args).execute
end

.execute_later(args = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flakes.rb', line 17

def self.execute_later(args = {})
  options = {}
  options[:wait] = args.delete(:wait) if args.key?(:wait)

  # initialize ActiveJob::Core only when Flake is enqueued to prevent conflics whith ActiveModel
  flake = new
  flake.send(:active_job_initialize, args)

  if queue_adapter.class.name.demodulize == "ResqueAdapter"
    flake.enqueue(options)
  else
    flake.enqueue
  end
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/flakes.rb', line 39

def execute(*)
  raise NotImplementedError, "no `execute` method defined for #{self.class}"
end

#on_failure(&callback) ⇒ Object



48
49
50
51
# File 'lib/flakes.rb', line 48

def on_failure(&callback)
  @failure = callback
  self
end

#on_success(&callback) ⇒ Object



43
44
45
46
# File 'lib/flakes.rb', line 43

def on_success(&callback)
  @success = callback
  self
end

#perform(args = {}) ⇒ Object



34
35
36
37
# File 'lib/flakes.rb', line 34

def perform(args = {})
  args.each { |key, value| instance_variable_set(:"@#{key}", value) }
  execute
end