Revision f8ad5591

b/daemons/ganeti-masterd
221 221
      return queue.ArchiveJob(job_id)
222 222

  
223 223
    elif method == luxi.REQ_AUTOARCHIVE_JOBS:
224
      age = args
225
      return queue.AutoArchiveJobs(age)
224
      (age, timeout) = args
225
      return queue.AutoArchiveJobs(age, timeout)
226 226

  
227 227
    elif method == luxi.REQ_WAIT_FOR_JOB_CHANGE:
228 228
      (job_id, fields, prev_job_info, prev_log_serial, timeout) = args
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.
b/lib/luxi.py
306 306
    return self.CallMethod(REQ_ARCHIVE_JOB, job_id)
307 307

  
308 308
  def AutoArchiveJobs(self, age):
309
    return self.CallMethod(REQ_AUTOARCHIVE_JOBS, age)
309
    timeout = (DEF_RWTO - 1) / 2
310
    return self.CallMethod(REQ_AUTOARCHIVE_JOBS, (age, timeout))
310 311

  
311 312
  def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial):
312 313
    timeout = (DEF_RWTO - 1) / 2
b/scripts/gnt-job
156 156
  else:
157 157
    age = ParseTimespec(age)
158 158

  
159
  client.AutoArchiveJobs(age)
159
  (archived_count, jobs_left) = client.AutoArchiveJobs(age)
160
  ToStdout("Archived %s jobs, %s unchecked left", archived_count, jobs_left)
161

  
160 162
  return 0
161 163

  
162 164

  

Also available in: Unified diff