Module: Lavin::Worker

Defined in:
lib/lavin/worker.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index=(value) ⇒ Object

Sets the attribute index

Parameters:

  • value

    the value to set the attribute index to.



35
36
37
# File 'lib/lavin/worker.rb', line 35

def index=(value)
  @index = value
end

Class Method Details

.included(base) ⇒ Object



31
32
33
# File 'lib/lavin/worker.rb', line 31

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(**kwargs) ⇒ Object



37
38
39
40
# File 'lib/lavin/worker.rb', line 37

def initialize(**kwargs)
  @task = kwargs.delete(:task)
  super(**kwargs)
end

#runObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lavin/worker.rb', line 42

def run
  catch(:stop_user) do
    self.class.before.run(context: self).then { Runner.yield } if self.class.before

    run_step until finished?
  end

  catch(:stop_user) do
    self.class.after.run(context: self).then { Runner.yield } if self.class.after
  end
end