Updated gems, fixed error on Ruby 3.2 (Thread block no longer passes self as argument), fixed API calls not timing out properly, fixed BackgroundWorker not halting properly.

This commit is contained in:
2023-02-03 12:19:18 -06:00
parent db12e56623
commit c73bd2d88b
3 changed files with 63 additions and 43 deletions

View File

@@ -71,12 +71,15 @@ class W3DHub
def kill!
@thread_pool.each(&:kill)
logger.info(LOG_TAG) { "Forcefully killed background job worker." }
@@alive = false
end
def handle_jobs
8.times do |i|
Thread.new do |thread|
@thread_pool << thread
Thread.new do
@thread_pool << Thread.current
while BackgroundWorker.run?
job = @parallel_jobs.shift
@@ -96,24 +99,28 @@ class W3DHub
end
end
while BackgroundWorker.run?
job = @jobs.shift
Thread.new do
@thread_pool << Thread.current
@busy = true
while BackgroundWorker.run?
job = @jobs.shift
begin
job&.do
rescue => e
job&.raise_error(e)
@busy = true
begin
job&.do
rescue => e
job&.raise_error(e)
end
@busy = !@jobs.empty?
sleep 0.1
end
@busy = !@jobs.empty?
sleep 0.1
logger.info(LOG_TAG) { "Stopped background job worker." }
@@alive = false
end
logger.info(LOG_TAG) { "Stopped background job worker." }
@@alive = false
end
def add_job(job)