lib/rocket_job/worker.rb in rocketjob-1.2.1 vs lib/rocket_job/worker.rb in rocketjob-1.3.0
- old
+ new
@@ -1,8 +1,7 @@
# encoding: UTF-8
require 'socket'
-require 'sync_attr'
require 'aasm'
module RocketJob
# Worker
#
# On startup a worker instance will automatically register itself
@@ -28,11 +27,10 @@
# immediately. Via the UI or Ruby code the worker can take up to 15 seconds
# (the heartbeat interval) to start shutting down.
class Worker
include MongoMapper::Document
include AASM
- include SyncAttr
include SemanticLogger::Loggable
# Prevent data in MongoDB from re-defining the model behavior
#self.static_keys = true
@@ -162,11 +160,11 @@
# Returns [Array<Thread>] threads in the thread_pool
def thread_pool
@thread_pool ||= []
end
- # Run this instance of the worker
+ # Management Thread
def run
Thread.current.name = 'rocketjob main'
build_heartbeat unless heartbeat
started
@@ -180,11 +178,11 @@
set(
'heartbeat.updated_at' => Time.now,
'heartbeat.current_threads' => thread_pool_count
)
- # Reload the worker model every 10 heartbeats in case its config was changed
+ # Reload the worker model every few heartbeats in case its config was changed
# TODO make 3 configurable
if count >= 3
reload
adjust_thread_pool
count = 0
@@ -314,13 +312,15 @@
def requeue_jobs
stop! if running? || paused?
RocketJob::Job.requeue_dead_worker(name)
end
- # Mutex protected shutdown indicator
- sync_cattr_accessor :shutdown do
- false
+ # Shutdown indicator
+ def self.shutdown
+ @@shutdown
end
+
+ @@shutdown = false
# Register handlers for the various signals
# Term:
# Perform clean shutdown
#