Class: LogStash::Outputs::File::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/file.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.



304
305
306
307
308
309
310
311
# File 'lib/logstash/outputs/file.rb', line 304

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

  require 'thread' # 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:



297
298
299
# File 'lib/logstash/outputs/file.rb', line 297

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

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


338
339
340
# File 'lib/logstash/outputs/file.rb', line 338

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

#startvoid

This method returns an undefined value.

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



317
318
319
320
321
322
323
# File 'lib/logstash/outputs/file.rb', line 317

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.



328
329
330
331
332
333
334
# File 'lib/logstash/outputs/file.rb', line 328

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

  @thread && @thread.join
end