Module: QueueDispatcher::ActsAsTaskQueue::SingletonMethods
- Defined in:
- lib/queue_dispatcher/acts_as_task_queue.rb
Instance Method Summary collapse
- #acts_as_task_queue_config ⇒ Object
-
#any_running? ⇒ Boolean
Are there any running task_queues?.
-
#find_or_create_by_name(name, options = {}) ⇒ Object
Find or create a task_queue by its name which is not in state ‘error’.
-
#get_next_pending ⇒ Object
Get next pending task_queue.
Instance Method Details
#acts_as_task_queue_config ⇒ Object
49 50 51 |
# File 'lib/queue_dispatcher/acts_as_task_queue.rb', line 49 def acts_as_task_queue_config @acts_as_task_queue_config end |
#any_running? ⇒ Boolean
Are there any running task_queues?
55 56 57 58 59 |
# File 'lib/queue_dispatcher/acts_as_task_queue.rb', line 55 def any_running? running = false all.each{ |tq| running = true if tq.running? || tq.brand_new? } running end |
#find_or_create_by_name(name, options = {}) ⇒ Object
Find or create a task_queue by its name which is not in state ‘error’. Create one, if there does not exists one
79 80 81 82 83 |
# File 'lib/queue_dispatcher/acts_as_task_queue.rb', line 79 def find_or_create_by_name name, = {} transaction do self.where(:name => name).where('state != "error"').first || self.create(:name => name, :state => 'new', terminate_immediately: [:terminate_immediately]) end end |
#get_next_pending ⇒ Object
Get next pending task_queue
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/queue_dispatcher/acts_as_task_queue.rb', line 63 def get_next_pending task_queue = nil transaction do # Find next task_queue which is not running and not in state error order(:id).lock(true).all.each { |tq| task_queue = tq unless task_queue || tq.pid_running? || tq.state == 'error' } # Update pid inside the atomic transaction to be sure, the next call of this method will not give the same queue a second time task_queue.update_attribute :pid, $$ if task_queue end task_queue end |