Revision 1410a389 lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
62 | 62 |
|
63 | 63 |
|
64 | 64 |
JOBQUEUE_THREADS = 25 |
65 |
JOBS_PER_ARCHIVE_DIRECTORY = 10000 |
|
66 | 65 |
|
67 | 66 |
# member lock names to be passed to @ssynchronized decorator |
68 | 67 |
_LOCK = "_lock" |
... | ... | |
1797 | 1796 |
result = self._GetRpc(addrs).call_jobqueue_rename(names, rename) |
1798 | 1797 |
self._CheckRpcResult(result, self._nodes, "Renaming files (%r)" % rename) |
1799 | 1798 |
|
1800 |
@staticmethod |
|
1801 |
def _FormatJobID(job_id): |
|
1802 |
"""Convert a job ID to string format. |
|
1803 |
|
|
1804 |
Currently this just does C{str(job_id)} after performing some |
|
1805 |
checks, but if we want to change the job id format this will |
|
1806 |
abstract this change. |
|
1807 |
|
|
1808 |
@type job_id: int or long |
|
1809 |
@param job_id: the numeric job id |
|
1810 |
@rtype: str |
|
1811 |
@return: the formatted job id |
|
1812 |
|
|
1813 |
""" |
|
1814 |
if not isinstance(job_id, (int, long)): |
|
1815 |
raise errors.ProgrammerError("Job ID '%s' not numeric" % job_id) |
|
1816 |
if job_id < 0: |
|
1817 |
raise errors.ProgrammerError("Job ID %s is negative" % job_id) |
|
1818 |
|
|
1819 |
return str(job_id) |
|
1820 |
|
|
1821 |
@classmethod |
|
1822 |
def _GetArchiveDirectory(cls, job_id): |
|
1823 |
"""Returns the archive directory for a job. |
|
1824 |
|
|
1825 |
@type job_id: str |
|
1826 |
@param job_id: Job identifier |
|
1827 |
@rtype: str |
|
1828 |
@return: Directory name |
|
1829 |
|
|
1830 |
""" |
|
1831 |
return str(int(job_id) / JOBS_PER_ARCHIVE_DIRECTORY) |
|
1832 |
|
|
1833 | 1799 |
def _NewSerialsUnlocked(self, count): |
1834 | 1800 |
"""Generates a new job identifier. |
1835 | 1801 |
|
... | ... | |
1850 | 1816 |
self._UpdateJobQueueFile(constants.JOB_QUEUE_SERIAL_FILE, |
1851 | 1817 |
"%s\n" % serial, True) |
1852 | 1818 |
|
1853 |
result = [self._FormatJobID(v)
|
|
1819 |
result = [jstore.FormatJobID(v)
|
|
1854 | 1820 |
for v in range(self._last_serial + 1, serial + 1)] |
1855 | 1821 |
|
1856 | 1822 |
# Keep it only if we were able to write the file |
... | ... | |
1872 | 1838 |
""" |
1873 | 1839 |
return utils.PathJoin(constants.QUEUE_DIR, "job-%s" % job_id) |
1874 | 1840 |
|
1875 |
@classmethod
|
|
1876 |
def _GetArchivedJobPath(cls, job_id):
|
|
1841 |
@staticmethod
|
|
1842 |
def _GetArchivedJobPath(job_id): |
|
1877 | 1843 |
"""Returns the archived job file for a give job id. |
1878 | 1844 |
|
1879 | 1845 |
@type job_id: str |
... | ... | |
1883 | 1849 |
|
1884 | 1850 |
""" |
1885 | 1851 |
return utils.PathJoin(constants.JOB_QUEUE_ARCHIVE_DIR, |
1886 |
cls._GetArchiveDirectory(job_id), "job-%s" % job_id) |
|
1852 |
jstore.GetArchiveDirectory(job_id), |
|
1853 |
"job-%s" % job_id) |
|
1887 | 1854 |
|
1888 | 1855 |
@staticmethod |
1889 | 1856 |
def _GetJobIDsUnlocked(sort=True): |
... | ... | |
2220 | 2187 |
|
2221 | 2188 |
""" |
2222 | 2189 |
if not isinstance(job_id, basestring): |
2223 |
job_id = self._FormatJobID(job_id)
|
|
2190 |
job_id = jstore.FormatJobID(job_id)
|
|
2224 | 2191 |
|
2225 | 2192 |
# Not using in-memory cache as doing so would require an exclusive lock |
2226 | 2193 |
|
Also available in: Unified diff