Sha256: 95072c9c53cd134cf36fd686538cd52fd878d4f62831db7ff6c8a1d1dc33ccbd
Contents?: true
Size: 910 Bytes
Versions: 1
Compression:
Stored size: 910 Bytes
Contents
# frozen_string_literal: true require_relative 'hard_worker/version' require_relative 'hard_worker/worker' require 'byebug' require 'drb' # HardWorker is a pure Ruby job backend. # It has limited functionality, as it only accepts # jobs as procs, but that might make it useful if you don't # need anything as big as Redis. # Loses all jobs if restarted. class HardWorker URI = 'druby://localhost:8788' @@queue = Queue.new def initialize(workers: 1, connect: false) @worker_list = [] workers.times do |_i| @worker_list << Thread.new { Worker.new } end return unless connect DRb.start_service(URI, @@queue) puts "listening on #{URI}" DRb.thread.join end def stop_workers @worker_list.each do |worker| Thread.kill(worker) end end def job_list @@queue end def self.fetch_job @@queue.pop end class Error < StandardError; end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hard_worker-0.0.1 | lib/hard_worker.rb |