Class: Raktr::Tasks::Periodic

Inherits:
Persistent show all
Defined in:
lib/raktr/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)


25
26
27
28
29
30
31
32
33
# File 'lib/raktr/tasks/periodic.rb', line 25

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)


20
21
22
# File 'lib/raktr/tasks/periodic.rb', line 20

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.



38
39
40
41
42
43
# File 'lib/raktr/tasks/periodic.rb', line 38

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

    super( *args )
end