Module: Systemd::Journal::Waitable

Included in:
Systemd::Journal
Defined in:
lib/systemd/journal/waitable.rb

Constant Summary collapse

IS_JRUBY =
(RUBY_ENGINE == 'jruby')

Instance Method Summary collapse

Instance Method Details

#wait(timeout_usec = -1,, opts = {}) ⇒ Nil, Symbol

Block until the journal is changed.

Examples:

Wait for an event for a maximum of 3 seconds

j = Systemd::Journal.new
j.seek(:tail)
if j.wait(3 * 1_000_000)
  # event occurred
end

Parameters:

  • timeout_usec (Integer) (defaults to: -1,)

    maximum number of microseconds to wait or ‘-1` to wait indefinitely.

Returns:

  • (Nil)

    the wait time was reached (no events occured).

  • (Symbol)

    :append new entries were appened to the journal.

  • (Symbol)

    :invalidate journal files were added/removed/rotated.



18
19
20
21
22
23
24
25
26
# File 'lib/systemd/journal/waitable.rb', line 18

def wait(timeout_usec = -1, opts = {})
  if opts[:select] && !IS_JRUBY
    wait_select(timeout_usec)
  else
    rc = Native.sd_journal_wait(@ptr, timeout_usec)
    raise JournalError, rc if rc.is_a?(Integer) && rc < 0
    rc == :nop ? nil : rc
  end
end

#wait_select_reliable?Boolean

Determine if calls to #wait with ‘select: true` will reliably wake when a change occurs. If false, there might be some (unknown) latency involved between when an change occurs and when #wait returns.

Returns:

  • (Boolean)


32
33
34
# File 'lib/systemd/journal/waitable.rb', line 32

def wait_select_reliable?
  Native.sd_journal_reliable_fd(@ptr) > 0
end

#watchObject

Block and wait for new entries to be appended to the journal. When new entries are written, yields them in turn. Note that this function does not automatically seek to the end of the journal prior to waiting. This method Does not return.

Examples:

Print out events as they happen

j = Systemd::Journal.new
j.seek(:tail)
j.watch do |event|
  puts event.message
end


46
47
48
# File 'lib/systemd/journal/waitable.rb', line 46

def watch
  loop { (yield current_entry while move_next) if wait }
end