Module: OpenWFE::WorkqueueMixin
- Included in:
- ExpressionPool
- Defined in:
- lib/openwfe/util/workqueue.rb
Overview
This mixin provides a workqueue and a thread for executing tasks pushed onto it. It uses the thread.rb Queue class.
It is currently only used by the ExpressionPool (maybe it’ll get merged back into it later).
Instance Method Summary collapse
-
#is_workqueue_busy? ⇒ Boolean
Returns true if there is or there just was activity for the work queue.
-
#queue_work(*args) ⇒ Object
the method called by the mixer to actually queue the work.
-
#start_workqueue ⇒ Object
Creates and starts the workqueue.
-
#stop_workqueue ⇒ Object
Stops the workqueue.
Instance Method Details
#is_workqueue_busy? ⇒ Boolean
Returns true if there is or there just was activity for the work queue.
76 77 78 79 |
# File 'lib/openwfe/util/workqueue.rb', line 76 def is_workqueue_busy? @workqueue.size > 0 end |
#queue_work(*args) ⇒ Object
the method called by the mixer to actually queue the work.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/openwfe/util/workqueue.rb', line 92 def queue_work (*args) if @workqueue_stopped do_process_workelement args # # degraded mode : as if there were no workqueue else @workqueue.push args # # work will be done later (millisec order) # by the work thread end end |
#start_workqueue ⇒ Object
Creates and starts the workqueue.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/openwfe/util/workqueue.rb', line 58 def start_workqueue @workqueue = Queue.new @workstopped = false OpenWFE::call_in_thread "workqueue", self do loop do do_process_workelement @workqueue.pop break if @workstopped and @workqueue.empty? end end end |
#stop_workqueue ⇒ Object
Stops the workqueue.
84 85 86 87 |
# File 'lib/openwfe/util/workqueue.rb', line 84 def stop_workqueue @workstopped = true end |