Sha256: 4b244689826157e07d8ea15d93fc8d4b99832a024ba6370bf74e22b8acd20f7d

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

module RocketJob
  module Subscribers
    class Server
      include RocketJob::Subscriber

      attr_reader :supervisor

      def initialize(supervisor)
        @supervisor = supervisor
      end

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

        supervisor.synchronize do
          supervisor.worker_pool.stop
          supervisor.worker_pool.join(wait_timeout)
          supervisor.worker_pool.kill
        end

        Supervisor.shutdown!
        logger.info "Killed"
      end

      def pause(server_id: nil)
        return unless my_server?(server_id)

        supervisor.synchronize { supervisor.server.pause! if supervisor.server.may_pause? }
        Supervisor.event!
        logger.info "Paused"
      end

      def refresh(server_id: nil)
        return unless my_server?(server_id)

        Supervisor.event!
        logger.info "Refreshed"
      end

      def resume(server_id: nil)
        return unless my_server?(server_id)

        supervisor.synchronize { supervisor.server.resume! if supervisor.server.may_resume? }
        Supervisor.event!
        logger.info "Resumed"
      end

      def stop(server_id: nil)
        return unless my_server?(server_id)

        Supervisor.shutdown!
        logger.info "Shutdown"
      end

      def thread_dump(server_id: nil)
        return unless my_server?(server_id)

        logger.info "Thread dump"
        supervisor.worker_pool.log_backtraces
      end

      private

      def my_server?(server_id)
        return true if server_id.nil?

        server_id == supervisor.server.id
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rocketjob-5.0.0 lib/rocket_job/subscribers/server.rb
rocketjob-5.0.0.rc1 lib/rocket_job/subscribers/server.rb
rocketjob-5.0.0.beta4 lib/rocket_job/subscribers/server.rb
rocketjob-5.0.0.beta3 lib/rocket_job/subscribers/server.rb
rocketjob-5.0.0.beta2 lib/rocket_job/subscribers/server.rb
rocketjob-5.0.0.beta lib/rocket_job/subscribers/server.rb
rocketjob-4.3.0.beta2 lib/rocket_job/subscribers/server.rb
rocketjob-4.3.0.beta lib/rocket_job/subscribers/server.rb
rocketjob-4.2.0 lib/rocket_job/subscribers/server.rb
rocketjob-4.1.1 lib/rocket_job/subscribers/server.rb
rocketjob-4.1.0 lib/rocket_job/subscribers/server.rb