Sha256: f48d116e303760925013a497338b7825f3d71b897423f3a09dca4ec42c7a0796
Contents?: true
Size: 893 Bytes
Versions: 1
Compression:
Stored size: 893 Bytes
Contents
# frozen_string_literal: true require_relative 'hard_worker/version' require_relative 'hard_worker/worker' 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.2 | lib/hard_worker.rb |