Sha256: 9ec4eda77dc8c29be006e87ab001454ae3001addd528abe17b60ae51c9b7f9db

Contents?: true

Size: 917 Bytes

Versions: 18

Compression:

Stored size: 917 Bytes

Contents

module ProconBypassMan
  module Background
    class JobRunner
      MAX_QUEUE_SIZE = 100

      def self.start!
        new.start!
      end

      # for test
      def stop!
        return unless defined?(@thread)
        @thread.kill
      end

      def start!
        return if defined?(@thread)
        @thread = Thread.new do
          while(item = self.class.queue.pop)
            begin
              JobPerformer.new(klass: item[:reporter_class], args: item[:args]).perform
              sleep(1)
            rescue => e
              ProconBypassMan.logger.error(e)
            end
          end
        end
        self
      end

      def self.queue
        @@queue ||= Queue.new
      end

      def self.push(hash)
        if queue.size > MAX_QUEUE_SIZE
          ProconBypassMan.logger.error('Over queue size cap!!')
          return
        end

        queue.push(hash)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
procon_bypass_man-0.2.2 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.22 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.21 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.20.2 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.20.1 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.20 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.19.1 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.19 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.18 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.17 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.16.1 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.16 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.15 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.14 lib/procon_bypass_man/background/job_runner.rb
procon_bypass_man-0.1.13 lib/procon_bypass_man/background/job_runner.rb