Revision c8d0be94 lib/jqueue.py

b/lib/jqueue.py
1487 1487
  return wrapper
1488 1488

  
1489 1489

  
1490
def _RequireNonDrainedQueue(fn):
1491
  """Decorator checking for a non-drained queue.
1492

  
1493
  To be used with functions submitting new jobs.
1494

  
1495
  """
1496
  def wrapper(self, *args, **kwargs):
1497
    """Wrapper function.
1498

  
1499
    @raise errors.JobQueueDrainError: if the job queue is marked for draining
1500

  
1501
    """
1502
    # Ok when sharing the big job queue lock, as the drain file is created when
1503
    # the lock is exclusive.
1504
    # Needs access to protected member, pylint: disable=W0212
1505
    if self._drained:
1506
      raise errors.JobQueueDrainError("Job queue is drained, refusing job")
1507
    return fn(self, *args, **kwargs)
1508
  return wrapper
1509

  
1510

  
1490 1511
class JobQueue(object):
1491 1512
  """Queue used to manage the jobs.
1492 1513

  
......
2013 2034
    @param ops: The list of OpCodes that will become the new job.
2014 2035
    @rtype: L{_QueuedJob}
2015 2036
    @return: the job object to be queued
2016
    @raise errors.JobQueueDrainError: if the job queue is marked for draining
2017 2037
    @raise errors.JobQueueFull: if the job queue has too many jobs in it
2018 2038
    @raise errors.GenericError: If an opcode is not valid
2019 2039

  
2020 2040
    """
2021
    # Ok when sharing the big job queue lock, as the drain file is created when
2022
    # the lock is exclusive.
2023
    if self._drained:
2024
      raise errors.JobQueueDrainError("Job queue is drained, refusing job")
2025

  
2026 2041
    if self._queue_size >= constants.JOB_QUEUE_SIZE_HARD_LIMIT:
2027 2042
      raise errors.JobQueueFull()
2028 2043

  
......
2054 2069

  
2055 2070
  @locking.ssynchronized(_LOCK)
2056 2071
  @_RequireOpenQueue
2072
  @_RequireNonDrainedQueue
2057 2073
  def SubmitJob(self, ops):
2058 2074
    """Create and store a new job.
2059 2075

  
......
2066 2082

  
2067 2083
  @locking.ssynchronized(_LOCK)
2068 2084
  @_RequireOpenQueue
2085
  @_RequireNonDrainedQueue
2069 2086
  def SubmitManyJobs(self, jobs):
2070 2087
    """Create and store multiple jobs.
2071 2088

  

Also available in: Unified diff