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) (defaults to: nil)

    optional user-defined command id

  • payload (any) (defaults to: nil)

    optional user-defined payload

  • priority (Integer) (defaults to: 10)

    lower number means higher priority



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

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)


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

def callable
  @callable
end

#idany

Returns:

  • (any)


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

def id
  @id
end

#orderInteger

Returns internal queue order.

Returns:

  • (Integer)

    internal queue order



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

def order
  @order
end

#priorityInteger

Returns:

  • (Integer)


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

def priority
  @priority
end

Instance Method Details

#<=>(other) ⇒ Object



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

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