Method: Que::JobBuffer#initialize
- Defined in:
- lib/que/job_buffer.rb
#initialize(maximum_size:, minimum_size:, priorities:) ⇒ JobBuffer
Since we use a mutex, which is not reentrant, we have to be a little careful to not call a method that locks the mutex when we’ve already locked it. So, as a general rule, public methods handle locking the mutex when necessary, while private methods handle the actual underlying data changes. This lets us reuse those private methods without running into locking issues.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/que/job_buffer.rb', line 18 def initialize( maximum_size:, minimum_size:, priorities: ) @maximum_size = Que.assert(Integer, maximum_size) Que.assert(maximum_size >= 0) { "maximum_size for a JobBuffer must be at least zero!" } @minimum_size = Que.assert(Integer, minimum_size) Que.assert(minimum_size >= 0) { "minimum_size for a JobBuffer must be at least zero!" } Que.assert(minimum_size <= maximum_size) do "minimum buffer size (#{minimum_size}) is " \ "greater than the maximum buffer size (#{maximum_size})!" end @stop = false @array = [] @mutex = Mutex.new @priority_queues = Hash[ # Make sure that priority = nil sorts highest. priorities.sort_by{|p| p || MAXIMUM_PRIORITY}.map do |p| [p, PriorityQueue.new(priority: p, job_buffer: self)] end ].freeze end |