Sha256: 6a252ef609fa27286380c727608f3cf9534fb04ed6daaf0a06525a8b3ca0a7d2

Contents?: true

Size: 933 Bytes

Versions: 12

Compression:

Stored size: 933 Bytes

Contents

module RocketJob
  # Run each worker in its own "Ractor".
  class RactorWorker < Worker
    attr_reader :thread

    def initialize(id:, server_name:)
      super(id: id, server_name: server_name)
      @shutdown = Concurrent::Event.new
      @thread   = Ractor.new(name: "rocketjob-#{id}") { run }
    end

    def alive?
      @thread.alive?
    end

    def backtrace
      @thread.backtrace
    end

    def join(*args)
      @thread.join(*args)
    end

    # Send each active worker the RocketJob::ShutdownException so that stops processing immediately.
    def kill
      @thread.raise(Shutdown, "Shutdown due to kill request for worker: #{name}") if @thread.alive?
    end

    def shutdown?
      @shutdown.set?
    end

    def shutdown!
      @shutdown.set
    end

    # Returns [true|false] whether the shutdown indicator was set
    def wait_for_shutdown?(timeout = nil)
      @shutdown.wait(timeout)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rocketjob-6.3.1 lib/rocket_job/ractor_worker.rb
rocketjob-6.3.0 lib/rocket_job/ractor_worker.rb
rocketjob-6.2.0 lib/rocket_job/ractor_worker.rb
rocketjob-6.1.1 lib/rocket_job/ractor_worker.rb
rocketjob-6.1.0 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.3 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.2 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.1 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.0 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.0.rc3 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.0.rc2 lib/rocket_job/ractor_worker.rb
rocketjob-6.0.0.rc1 lib/rocket_job/ractor_worker.rb