Revision 194c8ca4 lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
1608 | 1608 |
return job |
1609 | 1609 |
|
1610 | 1610 |
try: |
1611 |
job = self._LoadJobFromDisk(job_id) |
|
1611 |
job = self._LoadJobFromDisk(job_id, False)
|
|
1612 | 1612 |
if job is None: |
1613 | 1613 |
return job |
1614 | 1614 |
except errors.JobFileCorrupted: |
... | ... | |
1627 | 1627 |
logging.debug("Added job %s to the cache", job_id) |
1628 | 1628 |
return job |
1629 | 1629 |
|
1630 |
def _LoadJobFromDisk(self, job_id): |
|
1630 |
def _LoadJobFromDisk(self, job_id, try_archived):
|
|
1631 | 1631 |
"""Load the given job file from disk. |
1632 | 1632 |
|
1633 | 1633 |
Given a job file, read, load and restore it in a _QueuedJob format. |
1634 | 1634 |
|
1635 | 1635 |
@type job_id: string |
1636 | 1636 |
@param job_id: job identifier |
1637 |
@type try_archived: bool |
|
1638 |
@param try_archived: Whether to try loading an archived job |
|
1637 | 1639 |
@rtype: L{_QueuedJob} or None |
1638 | 1640 |
@return: either None or the job object |
1639 | 1641 |
|
1640 | 1642 |
""" |
1641 |
filepath = self._GetJobPath(job_id) |
|
1642 |
logging.debug("Loading job from %s", filepath) |
|
1643 |
try: |
|
1644 |
raw_data = utils.ReadFile(filepath) |
|
1645 |
except EnvironmentError, err: |
|
1646 |
if err.errno in (errno.ENOENT, ): |
|
1647 |
return None |
|
1648 |
raise |
|
1643 |
path_functions = [self._GetJobPath] |
|
1644 |
|
|
1645 |
if try_archived: |
|
1646 |
path_functions.append(self._GetArchivedJobPath) |
|
1647 |
|
|
1648 |
raw_data = None |
|
1649 |
|
|
1650 |
for fn in path_functions: |
|
1651 |
filepath = fn(job_id) |
|
1652 |
logging.debug("Loading job from %s", filepath) |
|
1653 |
try: |
|
1654 |
raw_data = utils.ReadFile(filepath) |
|
1655 |
except EnvironmentError, err: |
|
1656 |
if err.errno != errno.ENOENT: |
|
1657 |
raise |
|
1658 |
else: |
|
1659 |
break |
|
1660 |
|
|
1661 |
if not raw_data: |
|
1662 |
return None |
|
1649 | 1663 |
|
1650 | 1664 |
try: |
1651 | 1665 |
data = serializer.LoadJson(raw_data) |
... | ... | |
1655 | 1669 |
|
1656 | 1670 |
return job |
1657 | 1671 |
|
1658 |
def SafeLoadJobFromDisk(self, job_id): |
|
1672 |
def SafeLoadJobFromDisk(self, job_id, try_archived):
|
|
1659 | 1673 |
"""Load the given job file from disk. |
1660 | 1674 |
|
1661 | 1675 |
Given a job file, read, load and restore it in a _QueuedJob format. |
... | ... | |
1664 | 1678 |
|
1665 | 1679 |
@type job_id: string |
1666 | 1680 |
@param job_id: job identifier |
1681 |
@type try_archived: bool |
|
1682 |
@param try_archived: Whether to try loading an archived job |
|
1667 | 1683 |
@rtype: L{_QueuedJob} or None |
1668 | 1684 |
@return: either None or the job object |
1669 | 1685 |
|
1670 | 1686 |
""" |
1671 | 1687 |
try: |
1672 |
return self._LoadJobFromDisk(job_id) |
|
1688 |
return self._LoadJobFromDisk(job_id, try_archived)
|
|
1673 | 1689 |
except (errors.JobFileCorrupted, EnvironmentError): |
1674 | 1690 |
logging.exception("Can't load/parse job %s", job_id) |
1675 | 1691 |
return None |
... | ... | |
1835 | 1851 |
as such by the clients |
1836 | 1852 |
|
1837 | 1853 |
""" |
1838 |
load_fn = compat.partial(self.SafeLoadJobFromDisk, job_id) |
|
1854 |
load_fn = compat.partial(self.SafeLoadJobFromDisk, job_id, False)
|
|
1839 | 1855 |
|
1840 | 1856 |
helper = _WaitForJobChangesHelper() |
1841 | 1857 |
|
... | ... | |
2004 | 2020 |
list_all = True |
2005 | 2021 |
|
2006 | 2022 |
for job_id in job_ids: |
2007 |
job = self.SafeLoadJobFromDisk(job_id) |
|
2023 |
job = self.SafeLoadJobFromDisk(job_id, True)
|
|
2008 | 2024 |
if job is not None: |
2009 | 2025 |
jobs.append(job.GetInfo(fields)) |
2010 | 2026 |
elif not list_all: |
Also available in: Unified diff