Chromium Code Reviews| Index: dashboard/dashboard/pinpoint/models/job.py |
| diff --git a/dashboard/dashboard/pinpoint/models/job.py b/dashboard/dashboard/pinpoint/models/job.py |
| index 89454d259543a5e09eb7ad3c6d94eb205348576d..b4d4201dacbabdbaa4fd6ff80fa2ff92bae525f9 100644 |
| --- a/dashboard/dashboard/pinpoint/models/job.py |
| +++ b/dashboard/dashboard/pinpoint/models/job.py |
| @@ -5,14 +5,17 @@ |
| import collections |
| import logging |
| import numbers |
| +import os |
| from google.appengine.api import taskqueue |
| from google.appengine.ext import ndb |
| +from dashboard.common import utils |
| from dashboard.pinpoint import mann_whitney_u |
| from dashboard.pinpoint.models import attempt as attempt_module |
| from dashboard.pinpoint.models import change as change_module |
| from dashboard.pinpoint.models import quest as quest_module |
| +from dashboard.services import issue_tracker_service |
| # We want this to be fast to minimize overhead while waiting for tasks to |
| @@ -64,10 +67,14 @@ class Job(ndb.Model): |
| # If False, only run the Changes explicitly added by the user. |
| auto_explore = ndb.BooleanProperty(required=True) |
| + # TODO: The bug id is only used for posting bug comments when a job starts and |
| + # completes. This probably should not be the responsibility of Pinpoint. |
| + bug_id = ndb.IntegerProperty() |
|
perezju
2017/06/29 09:03:30
Note that, probably, we would still want to mainta
|
| + |
| state = ndb.PickleProperty(required=True) |
| @classmethod |
| - def New(cls, configuration, test_suite, test, metric, auto_explore): |
| + def New(cls, configuration, test_suite, test, metric, auto_explore, bug_id): |
| # Get list of quests. |
| quests = [quest_module.FindIsolate(configuration)] |
| if test_suite: |
| @@ -82,6 +89,7 @@ class Job(ndb.Model): |
| test=test, |
| metric=metric, |
| auto_explore=auto_explore, |
| + bug_id=bug_id, |
| state=_JobState(quests, _DEFAULT_MAX_ATTEMPTS)) |
| @property |
| @@ -98,10 +106,28 @@ class Job(ndb.Model): |
| return 'Completed' |
| + @property |
| + def url(self): |
| + return 'https://%s/job/%s' % (os.environ['HTTP_HOST'], self.job_id) |
| + |
| def AddChange(self, change): |
| self.state.AddChange(change) |
| def Start(self): |
| + self.Schedule() |
| + |
| + comment = 'Pinpoint job started.\n' + self.url |
| + issue_tracker = issue_tracker_service.IssueTrackerService( |
| + utils.ServiceAccountHttp()) |
| + issue_tracker.AddBugComment(self.bug_id, comment, send_email=False) |
| + |
| + def Complete(self): |
| + comment = 'Pinpoint job complete!\n' + self.url |
| + issue_tracker = issue_tracker_service.IssueTrackerService( |
| + utils.ServiceAccountHttp()) |
| + issue_tracker.AddBugComment(self.bug_id, comment, send_email=False) |
| + |
| + def Schedule(self): |
| task = taskqueue.add(queue_name='job-queue', url='/api/run/' + self.job_id, |
| countdown=_TASK_INTERVAL) |
| self.task = task.name |
| @@ -117,7 +143,9 @@ class Job(ndb.Model): |
| # Schedule moar task. |
| if work_left: |
| - self.Start() |
| + self.Schedule() |
| + else: |
| + self.Complete() |
| except BaseException as e: |
| self.exception = str(e) |
| raise |