Class: Async::Container::Notify::Log

Inherits:
Client
  • Object
show all
Defined in:
lib/async/container/notify/log.rb

Overview

Represents a client that uses a local log file to communicate readiness, status changes, etc.

Constant Summary collapse

NOTIFY_LOG =

The name of the environment variable which contains the path to the notification socket.

"NOTIFY_LOG"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#ready!, #reloading!, #restarting!, #status!, #stopping!

Constructor Details

#initialize(path) ⇒ Log

Initialize the notification client.



33
34
35
# File 'lib/async/container/notify/log.rb', line 33

def initialize(path)
	@path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



38
39
40
# File 'lib/async/container/notify/log.rb', line 38

def path
  @path
end

#The path to the UNIX socket used for sending messages to the controller.(pathtotheUNIXsocketused) ⇒ Object (readonly)



38
# File 'lib/async/container/notify/log.rb', line 38

attr :path

Class Method Details

.open!(environment = ENV) ⇒ Object

Open a notification client attached to the current NOTIFY_LOG if possible.



25
26
27
28
29
# File 'lib/async/container/notify/log.rb', line 25

def self.open!(environment = ENV)
	if path = self.path(environment)
		self.new(path)
	end
end

.path(environment = ENV) ⇒ Object



19
20
21
# File 'lib/async/container/notify/log.rb', line 19

def self.path(environment = ENV)
	environment[NOTIFY_LOG]
end

Instance Method Details

#error!(text, **message) ⇒ Object

Send the specified error. ‘sd_notify` requires an `errno` key, which defaults to `-1` to indicate a generic error.



52
53
54
55
56
# File 'lib/async/container/notify/log.rb', line 52

def error!(text, **message)
	message[:errno] ||= -1
	
	super
end

#send(**message) ⇒ Object

Send the given message.



42
43
44
45
46
47
48
# File 'lib/async/container/notify/log.rb', line 42

def send(**message)
	data = JSON.dump(message)
	
	File.open(@path, "a") do |file|
		file.puts(data)
	end
end