Class: LogStash::Outputs::Kusto::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/kusto/interval.rb

Overview

Bare-bones utility for running a block of code at an interval.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval, procsy) ⇒ Interval

Returns a new instance of Interval.

Parameters:

  • interval (Integer)

    : time in seconds to wait between calling the given proc

  • procsy (#call)

    : proc or lambda to call periodically; must not raise exceptions.



28
29
30
31
32
33
34
35
# File 'lib/logstash/outputs/kusto/interval.rb', line 28

def initialize(interval, procsy)
  @interval = interval
  @procsy = procsy

  # Mutex, ConditionVariable, etc.
  @mutex = Mutex.new
  @sleeper = ConditionVariable.new
end

Class Method Details

.start(interval, procsy) ⇒ Interval

Initializes a new Interval with the given arguments and starts it before returning it.

Parameters:

  • interval (Integer)

    (see: Interval#initialize)

  • procsy (#call)

    (see: Interval#initialize)

Returns:



21
22
23
# File 'lib/logstash/outputs/kusto/interval.rb', line 21

def self.start(interval, procsy)
  new(interval, procsy).tap(&:start)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/logstash/outputs/kusto/interval.rb', line 62

def alive?
  @thread && @thread.alive?
end

#startvoid

This method returns an undefined value.

Starts the interval, or returns if it has already been started.



41
42
43
44
45
46
47
# File 'lib/logstash/outputs/kusto/interval.rb', line 41

def start
  @mutex.synchronize do
    return if @thread && @thread.alive?

    @thread = Thread.new { run }
  end
end

#stopObject

Stop the interval. Does not interrupt if execution is in-progress.



52
53
54
55
56
57
58
# File 'lib/logstash/outputs/kusto/interval.rb', line 52

def stop
  @mutex.synchronize do
    @stopped = true
  end

  @thread && @thread.join
end