Class: OsCtld::ContinuousExecutor::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/continuous_executor.rb

Overview

Queueable command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, payload: nil, priority: 10, &block) ⇒ Command

Returns a new instance of Command

Parameters:

  • id (any)

    optional user-defined command id

  • payload (any)

    optional user-defined payload

  • priority (Integer)

    lower number means higher priority



29
30
31
32
33
34
# File 'lib/osctld/continuous_executor.rb', line 29

def initialize(id: nil, payload: nil, priority: 10, &block)
  @id = id
  @priority = priority
  @callable = block if block
  @order = 1000
end

Instance Attribute Details

#callableMethod, Proc

Returns:

  • (Method, Proc)


21
22
23
# File 'lib/osctld/continuous_executor.rb', line 21

def callable
  @callable
end

#idany

Returns:

  • (any)


15
16
17
# File 'lib/osctld/continuous_executor.rb', line 15

def id
  @id
end

#orderInteger

Returns internal queue order

Returns:

  • (Integer)

    internal queue order



24
25
26
# File 'lib/osctld/continuous_executor.rb', line 24

def order
  @order
end

#priorityInteger

Returns:

  • (Integer)


18
19
20
# File 'lib/osctld/continuous_executor.rb', line 18

def priority
  @priority
end

Instance Method Details

#<=>(other) ⇒ Object



36
37
38
# File 'lib/osctld/continuous_executor.rb', line 36

def <=>(other)
  [priority, order] <=> [other.priority, other.order]
end

#done(retval) ⇒ Object (protected)



51
52
53
# File 'lib/osctld/continuous_executor.rb', line 51

def done(retval)
  @return_queue << retval if @return_queue
end

#execObject (protected)



47
48
49
# File 'lib/osctld/continuous_executor.rb', line 47

def exec
  callable.call(self)
end

#return_queueObject (protected)



43
44
45
# File 'lib/osctld/continuous_executor.rb', line 43

def return_queue
  @return_queue ||= OsCtl::Lib::Queue.new
end