Sha256: ce9f37216218c21b06445232482493ff39fc87c8e6eecc6f4a3d1e1f092b9860

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 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, name: nil, wait_timeout: 3)
        return unless my_server?(server_id, name)

        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, name: nil)
        return unless my_server?(server_id, name)

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

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

        Supervisor.event!
        logger.info "Refreshed"
      end

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

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

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

        Supervisor.shutdown!
        logger.info "Shutdown"
      end

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

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

      private

      def my_server?(server_id, name)
        return true if server_id.nil? && name.nil?
        return true if supervisor.server.name == name

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rocketjob-5.3.1 lib/rocket_job/subscribers/server.rb
rocketjob-5.3.0 lib/rocket_job/subscribers/server.rb
rocketjob-5.2.0 lib/rocket_job/subscribers/server.rb
rocketjob-5.2.0.beta3 lib/rocket_job/subscribers/server.rb
rocketjob-5.2.0.beta2 lib/rocket_job/subscribers/server.rb
rocketjob-5.2.0.beta1 lib/rocket_job/subscribers/server.rb
rocketjob-5.1.1 lib/rocket_job/subscribers/server.rb
rocketjob-5.1.0 lib/rocket_job/subscribers/server.rb