Class: Izanami::Channel
- Inherits:
-
Object
- Object
- Izanami::Channel
- Defined in:
- lib/izanami/channel.rb
Overview
Open a communication channel between workers to handle the output of a command.
A channel does two things: it publish and reads the data sent by a worker to a Redis pub/sub channel and stores that data when the channel is closed. That way, a process can read the output of a command when this is been executed or when is finished.
Defined Under Namespace
Classes: Input
Constant Summary collapse
- EOC =
End Of Channel
'--EOC--'
- SEPARATOR =
"\n"
Instance Method Summary collapse
-
#initialize(mapper) ⇒ Channel
constructor
A new instance of Channel.
-
#read(id) {|String| ... } ⇒ Object
Opens the channel for reading.
-
#write(id) {|Izanami::Channel::Input| ... } ⇒ Izanami::Channel::Input
Opens the channel to write.
Constructor Details
#initialize(mapper) ⇒ Channel
Returns a new instance of Channel.
64 65 66 |
# File 'lib/izanami/channel.rb', line 64 def initialize(mapper) @mapper = mapper end |
Instance Method Details
#read(id) {|String| ... } ⇒ Object
Opens the channel for reading.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/izanami/channel.rb', line 93 def read(id, &block) command = @mapper.find(id) || {} output = command['output'] if output read_string(output, &block) else read_buffer(id, &block) end end |
#write(id) {|Izanami::Channel::Input| ... } ⇒ Izanami::Channel::Input
Note:
if a block is given, the input is closed when the block
Opens the channel to write.
finish. If not, the client of the channel must close it.
78 79 80 81 82 83 84 85 86 |
# File 'lib/izanami/channel.rb', line 78 def write(id) input = Input.new(@mapper, id) if block_given? yield input input.close end input end |