Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 1 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """High level tasks execution scheduling API. | 5 """High level tasks execution scheduling API. |
| 6 | 6 |
| 7 This is the interface closest to the HTTP handlers. | 7 This is the interface closest to the HTTP handlers. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import datetime | 10 import datetime |
| 11 import logging | 11 import logging |
| 12 import math | 12 import math |
| 13 import random | 13 import random |
| 14 | 14 |
| 15 from google.appengine.ext import ndb | 15 from google.appengine.ext import ndb |
| 16 | 16 |
| 17 from components import auth | 17 from components import auth |
| 18 from components import datastore_utils | 18 from components import datastore_utils |
| 19 from components import pubsub | 19 from components import pubsub |
| 20 from components import utils | 20 from components import utils |
| 21 | 21 |
| 22 import event_mon_metrics | |
| 22 import ts_mon_metrics | 23 import ts_mon_metrics |
| 23 | 24 |
| 24 from server import acl | 25 from server import acl |
| 25 from server import config | 26 from server import config |
| 26 from server import stats | 27 from server import stats |
| 27 from server import task_pack | 28 from server import task_pack |
| 28 from server import task_request | 29 from server import task_request |
| 29 from server import task_result | 30 from server import task_result |
| 30 from server import task_to_run | 31 from server import task_to_run |
| 31 | 32 |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 assert bool(error) != bool(run_result), (error, run_result) | 806 assert bool(error) != bool(run_result), (error, run_result) |
| 806 if error: | 807 if error: |
| 807 logging.error('Task %s %s', packed, error) | 808 logging.error('Task %s %s', packed, error) |
| 808 return None | 809 return None |
| 809 # Caller must retry if PubSub enqueue fails. | 810 # Caller must retry if PubSub enqueue fails. |
| 810 task_completed = run_result.state != task_result.State.RUNNING | 811 task_completed = run_result.state != task_result.State.RUNNING |
| 811 if not _maybe_pubsub_notify_now(smry, request): | 812 if not _maybe_pubsub_notify_now(smry, request): |
| 812 return None | 813 return None |
| 813 _update_stats(run_result, bot_id, request, task_completed) | 814 _update_stats(run_result, bot_id, request, task_completed) |
| 814 if task_completed: | 815 if task_completed: |
| 816 event_mon_metrics.send_task_event(smry) | |
|
M-A Ruel
2016/11/28 16:56:32
I'm concerned in adding more synchronous I/O in th
Paweł Hajdan Jr.
2016/11/29 14:37:33
I'm also concerned. How about proactively requesti
M-A Ruel
2016/11/29 14:48:40
As long as it is quick to disable the functionalit
| |
| 815 ts_mon_metrics.update_jobs_completed_metrics(smry) | 817 ts_mon_metrics.update_jobs_completed_metrics(smry) |
| 816 return run_result.state | 818 return run_result.state |
| 817 | 819 |
| 818 | 820 |
| 819 def bot_kill_task(run_result_key, bot_id): | 821 def bot_kill_task(run_result_key, bot_id): |
| 820 """Terminates a task that is currently running as an internal failure. | 822 """Terminates a task that is currently running as an internal failure. |
| 821 | 823 |
| 822 Returns: | 824 Returns: |
| 823 str if an error message. | 825 str if an error message. |
| 824 """ | 826 """ |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 ## Task queue tasks. | 999 ## Task queue tasks. |
| 998 | 1000 |
| 999 | 1001 |
| 1000 def task_handle_pubsub_task(payload): | 1002 def task_handle_pubsub_task(payload): |
| 1001 """Handles task enqueued by _maybe_pubsub_notify_via_tq.""" | 1003 """Handles task enqueued by _maybe_pubsub_notify_via_tq.""" |
| 1002 # Do not catch errors to trigger task queue task retry. Errors should not | 1004 # Do not catch errors to trigger task queue task retry. Errors should not |
| 1003 # happen in normal case. | 1005 # happen in normal case. |
| 1004 _pubsub_notify( | 1006 _pubsub_notify( |
| 1005 payload['task_id'], payload['topic'], | 1007 payload['task_id'], payload['topic'], |
| 1006 payload['auth_token'], payload['userdata']) | 1008 payload['auth_token'], payload['userdata']) |
| OLD | NEW |