Sha256: d32af1cb5ebbfdbf572fd8d9296f5f58b9c698111f18040124b6741b39190c74

Contents?: true

Size: 1.87 KB

Versions: 26

Compression:

Stored size: 1.87 KB

Contents

#
# ServerEngine
#
# Copyright (C) 2012-2013 Sadayuki Furuhashi
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
require 'serverengine/signals'
require 'serverengine/signal_thread'

module ServerEngine

  class Worker
    def initialize(server, worker_id)
      @server = server
      @logger = @server.logger
      @worker_id = worker_id
    end

    attr_reader :server, :worker_id
    attr_accessor :logger

    def config
      @server.config
    end

    def before_fork
    end

    def run
      raise NoMethodError, "Worker#run method is not implemented"
    end

    def spawn(process_manager)
      raise NoMethodError, "Worker#spawn(process_manager) method is required for worker_type=spawn"
    end

    def stop
    end

    def reload
    end

    def after_start
    end

    def dump
      Sigdump.dump unless config[:disable_sigdump]
    end

    def install_signal_handlers
      w = self
      SignalThread.new do |st|
        st.trap(Signals::GRACEFUL_STOP) { w.stop }
        st.trap(Signals::IMMEDIATE_STOP, 'SIG_DFL')

        st.trap(Signals::GRACEFUL_RESTART) { w.stop }
        st.trap(Signals::IMMEDIATE_RESTART, 'SIG_DFL')

        st.trap(Signals::RELOAD) {
          w.logger.reopen!
          w.reload
        }
        st.trap(Signals::DETACH) { w.stop }

        st.trap(Signals::DUMP) { w.dump }
      end
    end

    def main
      run
    end
  end
end

Version data entries

26 entries across 26 versions & 5 rubygems

Version Path
serverengine-2.4.0 lib/serverengine/worker.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/lib/serverengine/worker.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/lib/serverengine/worker.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/lib/serverengine/worker.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/serverengine-2.3.2/lib/serverengine/worker.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/serverengine-2.3.2/lib/serverengine/worker.rb
serverengine-2.3.2 lib/serverengine/worker.rb
serverengine-2.3.1 lib/serverengine/worker.rb
serverengine-2.3.0 lib/serverengine/worker.rb
serverengine-2.2.5-x86-mingw32 lib/serverengine/worker.rb
serverengine-2.2.5-x64-mingw32 lib/serverengine/worker.rb
serverengine-2.2.5 lib/serverengine/worker.rb
serverengine-2.2.4-x86-mingw32 lib/serverengine/worker.rb
serverengine-2.2.4-x64-mingw32 lib/serverengine/worker.rb
serverengine-2.2.4 lib/serverengine/worker.rb
serverengine-2.2.3 lib/serverengine/worker.rb
serverengine-2.2.2 lib/serverengine/worker.rb
serverengine-2.2.1 lib/serverengine/worker.rb
serverengine-2.2.0 lib/serverengine/worker.rb
serverengine-2.1.1-x86-mingw32 lib/serverengine/worker.rb