Sha256: 3e4b960c35bf45577f5d778121cfc20cf32dedc9fc464700e179b7d101160398

Contents?: true

Size: 1.32 KB

Versions: 37

Compression:

Stored size: 1.32 KB

Contents

module RocketJob
  module Subscribers
    class Worker
      include RocketJob::Subscriber

      attr_reader :supervisor

      def initialize(supervisor)
        @supervisor = supervisor
      end

      def kill(server_id:, worker_id:, wait_timeout: 3)
        return unless my_server?(server_id)

        worker = locate_worker(worker_id)
        return unless worker

        worker.shutdown!
        worker.join(wait_timeout)
        worker.kill

        logger.info "Killed"
      end

      def stop(server_id:, worker_id:)
        return unless my_server?(server_id)

        worker = locate_worker(worker_id)
        return unless worker

        worker.shutdown!
        logger.info "Stopped Worker: #{worker_id}"
      end

      def thread_dump(server_id:, worker_id:)
        return unless my_server?(server_id)

        worker = locate_worker(worker_id)
        return unless worker

        logger.info "Thread dump Worker: #{worker_id}"
        logger.backtrace(thread: worker.thread) if worker.thread && worker.alive?
      end

      private

      def my_server?(server_id)
        server_id == supervisor.server.id
      end

      def locate_worker(worker_id)
        return unless worker_id

        worker = supervisor.worker_pool.find(worker_id)
        return unless worker&.alive?

        worker
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
rocketjob-6.3.1 lib/rocket_job/subscribers/worker.rb
rocketjob-6.3.0 lib/rocket_job/subscribers/worker.rb
rocketjob-6.2.0 lib/rocket_job/subscribers/worker.rb
rocketjob-6.1.1 lib/rocket_job/subscribers/worker.rb
rocketjob-6.1.0 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.3 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.2 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.1 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.0 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.0.rc3 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.0.rc2 lib/rocket_job/subscribers/worker.rb
rocketjob-6.0.0.rc1 lib/rocket_job/subscribers/worker.rb
rocketjob-5.4.1 lib/rocket_job/subscribers/worker.rb
rocketjob-5.4.0 lib/rocket_job/subscribers/worker.rb
rocketjob-5.4.0.beta2 lib/rocket_job/subscribers/worker.rb
rocketjob-5.4.0.beta1 lib/rocket_job/subscribers/worker.rb
rocketjob-5.3.3 lib/rocket_job/subscribers/worker.rb
rocketjob-5.3.2 lib/rocket_job/subscribers/worker.rb
rocketjob-5.3.1 lib/rocket_job/subscribers/worker.rb
rocketjob-5.3.0 lib/rocket_job/subscribers/worker.rb