Revision 793a8f7c lib/rapi/rlib2.py
b/lib/rapi/rlib2.py | ||
---|---|---|
83 | 83 |
"R": _NR_REGULAR, |
84 | 84 |
} |
85 | 85 |
|
86 |
# Timeout for /2/jobs/[job_id]/wait. Gives job up to 10 seconds to change. |
|
87 |
_WFJC_TIMEOUT = 10 |
|
88 |
|
|
86 | 89 |
|
87 | 90 |
class R_version(baserlib.R_Generic): |
88 | 91 |
"""/version resource. |
... | ... | |
211 | 214 |
return result |
212 | 215 |
|
213 | 216 |
|
217 |
class R_2_jobs_id_wait(baserlib.R_Generic): |
|
218 |
"""/2/jobs/[job_id]/wait resource. |
|
219 |
|
|
220 |
""" |
|
221 |
# WaitForJobChange provides access to sensitive information and blocks |
|
222 |
# machine resources (it's a blocking RAPI call), hence restricting access. |
|
223 |
GET_ACCESS = [rapi.RAPI_ACCESS_WRITE] |
|
224 |
|
|
225 |
def GET(self): |
|
226 |
"""Waits for job changes. |
|
227 |
|
|
228 |
""" |
|
229 |
job_id = self.items[0] |
|
230 |
|
|
231 |
fields = self.getBodyParameter("fields") |
|
232 |
prev_job_info = self.getBodyParameter("previous_job_info", None) |
|
233 |
prev_log_serial = self.getBodyParameter("previous_log_serial", None) |
|
234 |
|
|
235 |
if not isinstance(fields, list): |
|
236 |
raise http.HttpBadRequest("The 'fields' parameter should be a list") |
|
237 |
|
|
238 |
if not (prev_job_info is None or isinstance(prev_job_info, list)): |
|
239 |
raise http.HttpBadRequest("The 'previous_job_info' parameter should" |
|
240 |
" be a list") |
|
241 |
|
|
242 |
if not (prev_log_serial is None or |
|
243 |
isinstance(prev_log_serial, (int, long))): |
|
244 |
raise http.HttpBadRequest("The 'previous_log_serial' parameter should" |
|
245 |
" be a number") |
|
246 |
|
|
247 |
client = baserlib.GetClient() |
|
248 |
result = client.WaitForJobChangeOnce(job_id, fields, |
|
249 |
prev_job_info, prev_log_serial, |
|
250 |
timeout=_WFJC_TIMEOUT) |
|
251 |
if not result: |
|
252 |
raise http.HttpNotFound() |
|
253 |
|
|
254 |
if result == constants.JOB_NOTCHANGED: |
|
255 |
# No changes |
|
256 |
return None |
|
257 |
|
|
258 |
(job_info, log_entries) = result |
|
259 |
|
|
260 |
return { |
|
261 |
"job_info": job_info, |
|
262 |
"log_entries": log_entries, |
|
263 |
} |
|
264 |
|
|
265 |
|
|
214 | 266 |
class R_2_nodes(baserlib.R_Generic): |
215 | 267 |
"""/2/nodes resource. |
216 | 268 |
|
Also available in: Unified diff