Class: Arachni::Reactor::Tasks::Periodic

Inherits:
Persistent show all
Defined in:
lib/arachni/reactor/tasks/periodic.rb

Overview

Note:

Time accuracy cannot be guaranteed.

Task occurring every #interval seconds.

Author:

Direct Known Subclasses

Delayed

Instance Attribute Summary collapse

Attributes inherited from Base

#owner

Instance Method Summary collapse

Methods inherited from Base

#done, #hash, #to_proc

Constructor Details

#initialize(interval, &task) ⇒ Periodic

Returns a new instance of Periodic.

Parameters:

  • interval (Float)

    Needs to be greater than 0.0.

  • task (#call)


26
27
28
29
30
31
32
33
34
# File 'lib/arachni/reactor/tasks/periodic.rb', line 26

def initialize( interval, &task )
    interval = interval.to_f
    fail ArgumentError, 'Interval needs to be greater than 0.' if interval <= 0

    super( &task )

    @interval = interval
    calculate_next
end

Instance Attribute Details

#intervalFloat (readonly)

Returns:

  • (Float)


21
22
23
# File 'lib/arachni/reactor/tasks/periodic.rb', line 21

def interval
  @interval
end

Instance Method Details

#call(*args) ⇒ Object?

Return value of the configured task or nil if it's not time yet.

Returns:

  • (Object, nil)

    Return value of the configured task or nil if it's not time yet.



39
40
41
42
43
44
# File 'lib/arachni/reactor/tasks/periodic.rb', line 39

def call( *args )
    return if !call?
    calculate_next

    super( *args )
end