Class: Modal::ContainerProcessOutputStream
- Inherits:
-
Object
- Object
- Modal::ContainerProcessOutputStream
- Defined in:
- lib/modal/sandbox.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(exec_id, file_descriptor, decode_text) ⇒ ContainerProcessOutputStream
constructor
A new instance of ContainerProcessOutputStream.
Constructor Details
#initialize(exec_id, file_descriptor, decode_text) ⇒ ContainerProcessOutputStream
Returns a new instance of ContainerProcessOutputStream.
286 287 288 289 290 291 292 |
# File 'lib/modal/sandbox.rb', line 286 def initialize(exec_id, file_descriptor, decode_text) @exec_id = exec_id @file_descriptor = file_descriptor @decode_text = decode_text @last_batch_index = 0 @finished = false end |
Instance Method Details
#each ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/modal/sandbox.rb', line 294 def each return enum_for(:each) unless block_given? return if @finished begin request = Modal::Client::ContainerExecGetOutputRequest.new( exec_id: @exec_id, file_descriptor: @file_descriptor, timeout: 55, get_raw_bytes: true, last_batch_index: @last_batch_index ) stream = Modal.client.call(:container_exec_get_output, request) stream.each do |batch| @last_batch_index = batch.batch_index if batch.respond_to?(:batch_index) if batch.respond_to?(:items) && batch.items batch.items.each do |item| if item. && !item..empty? yield item. end end end if (batch.respond_to?(:has_exit_code) && batch.has_exit_code) || batch.items.empty? break end end rescue GRPC::BadStatus => e if e.code == GRPC::Core::StatusCodes::DEADLINE_EXCEEDED else raise e end end @finished = true end |