Revision f8ad5591 lib/jqueue.py
b/lib/jqueue.py | ||
---|---|---|
1171 | 1171 |
|
1172 | 1172 |
@utils.LockedMethod |
1173 | 1173 |
@_RequireOpenQueue |
1174 |
def AutoArchiveJobs(self, age): |
|
1174 |
def AutoArchiveJobs(self, age, timeout):
|
|
1175 | 1175 |
"""Archives all jobs based on age. |
1176 | 1176 |
|
1177 | 1177 |
The method will archive all jobs which are older than the age |
... | ... | |
1186 | 1186 |
logging.info("Archiving jobs with age more than %s seconds", age) |
1187 | 1187 |
|
1188 | 1188 |
now = time.time() |
1189 |
for job_id in self._GetJobIDsUnlocked(archived=False): |
|
1189 |
end_time = now + timeout |
|
1190 |
archived_count = 0 |
|
1191 |
last_touched = 0 |
|
1192 |
|
|
1193 |
all_job_ids = self._GetJobIDsUnlocked(archived=False) |
|
1194 |
for idx, job_id in enumerate(all_job_ids): |
|
1195 |
last_touched = idx |
|
1196 |
|
|
1197 |
if time.time() > end_time: |
|
1198 |
break |
|
1199 |
|
|
1190 | 1200 |
# Returns None if the job failed to load |
1191 | 1201 |
job = self._LoadJobUnlocked(job_id) |
1192 |
if not job:
|
|
1193 |
continue
|
|
1194 |
|
|
1195 |
if job.end_timestamp is None:
|
|
1196 |
if job.start_timestamp is None:
|
|
1197 |
job_age = job.received_timestamp
|
|
1202 |
if job: |
|
1203 |
if job.end_timestamp is None:
|
|
1204 |
if job.start_timestamp is None: |
|
1205 |
job_age = job.received_timestamp
|
|
1206 |
else:
|
|
1207 |
job_age = job.start_timestamp
|
|
1198 | 1208 |
else: |
1199 |
job_age = job.start_timestamp |
|
1200 |
else: |
|
1201 |
job_age = job.end_timestamp |
|
1209 |
job_age = job.end_timestamp |
|
1210 |
|
|
1211 |
if age == -1 or now - job_age[0] > age: |
|
1212 |
archived = self._ArchiveJobUnlocked(job) |
|
1213 |
if archived: |
|
1214 |
archived_count += 1 |
|
1215 |
continue |
|
1216 |
|
|
1202 | 1217 |
|
1203 |
if age == -1 or now - job_age[0] > age: |
|
1204 |
self._ArchiveJobUnlocked(job) |
|
1218 |
return (archived_count, len(all_job_ids) - last_touched - 1) |
|
1205 | 1219 |
|
1206 | 1220 |
def _GetJobInfoUnlocked(self, job, fields): |
1207 | 1221 |
"""Returns information about a job. |
Also available in: Unified diff