Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: appengine/swarming/server/task_result.py

Issue 2914803004: Fix non-idempotent task that /poll reaped but returned HTTP 500. (Closed)
Patch Set: Rebase on 2927053002 to reduce delta Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 """Task execution result models. 5 """Task execution result models.
6 6
7 This module doesn't do the scheduling itself. It only describes the entities to 7 This module doesn't do the scheduling itself. It only describes the entities to
8 store tasks results. 8 store tasks results.
9 9
10 - TaskResultSummary represents the overall result for the TaskRequest taking in 10 - TaskResultSummary represents the overall result for the TaskRequest taking in
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 from components import datastore_utils 77 from components import datastore_utils
78 from components import utils 78 from components import utils
79 from server import large 79 from server import large
80 from server import task_pack 80 from server import task_pack
81 from server import task_request 81 from server import task_request
82 82
83 import cipd 83 import cipd
84 84
85 # Amount of time after which a bot is considered dead. In short, if a bot has 85 # Amount of time after which a bot is considered dead. In short, if a bot has
86 # not ping in the last 5 minutes while running a task, it is considered dead. 86 # not ping in the last 2 minutes while running a task, it is considered dead.
87 BOT_PING_TOLERANCE = datetime.timedelta(seconds=5*60) 87 #
88 # task_runner.MAX_PACKET_INTERVAL is 30 seconds.
89 BOT_PING_TOLERANCE = datetime.timedelta(seconds=2*60)
88 90
89 91
90 class State(object): 92 class State(object):
91 """States in which a task can be. 93 """States in which a task can be.
92 94
93 It's in fact an enum. Values should be in decreasing order of importance. 95 It's in fact an enum. Values should be in decreasing order of importance.
94 """ 96 """
95 RUNNING = 0x10 # 16 97 RUNNING = 0x10 # 16
96 PENDING = 0x20 # 32 98 PENDING = 0x20 # 32
97 EXPIRED = 0x30 # 48 99 EXPIRED = 0x30 # 48
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 output, 736 output,
735 output_chunk_start) 737 output_chunk_start)
736 assert self.stdout_chunks <= TaskOutput.PUT_MAX_CHUNKS 738 assert self.stdout_chunks <= TaskOutput.PUT_MAX_CHUNKS
737 return entities 739 return entities
738 740
739 def to_dict(self): 741 def to_dict(self):
740 out = super(TaskRunResult, self).to_dict() 742 out = super(TaskRunResult, self).to_dict()
741 out['try_number'] = self.try_number 743 out['try_number'] = self.try_number
742 return out 744 return out
743 745
746 def _pre_put_hook(self):
747 super(TaskRunResult, self)._pre_put_hook()
748 if not self.started_ts:
749 raise datastore_errors.BadValueError('Must update .started_ts')
750
744 751
745 class TaskResultSummary(_TaskResultCommon): 752 class TaskResultSummary(_TaskResultCommon):
746 """Represents the overall result of a task. 753 """Represents the overall result of a task.
747 754
748 Parent is a TaskRequest. Key id is always 1. 755 Parent is a TaskRequest. Key id is always 1.
749 756
750 This includes the relevant result taking in account all tries. This entity is 757 This includes the relevant result taking in account all tries. This entity is
751 basically a cache plus a bunch of indexes to speed up common queries. 758 basically a cache plus a bunch of indexes to speed up common queries.
752 759
753 It's primary purpose is for status pages listing all the active tasks or 760 It's primary purpose is for status pages listing all the active tasks or
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1168
1162 The caller must save it in the DB. 1169 The caller must save it in the DB.
1163 """ 1170 """
1164 assert isinstance(request, task_request.TaskRequest) 1171 assert isinstance(request, task_request.TaskRequest)
1165 summary_key = task_pack.request_key_to_result_summary_key(request.key) 1172 summary_key = task_pack.request_key_to_result_summary_key(request.key)
1166 return TaskRunResult( 1173 return TaskRunResult(
1167 key=task_pack.result_summary_key_to_run_result_key( 1174 key=task_pack.result_summary_key_to_run_result_key(
1168 summary_key, try_number), 1175 summary_key, try_number),
1169 bot_dimensions=bot_dimensions, 1176 bot_dimensions=bot_dimensions,
1170 bot_id=bot_id, 1177 bot_id=bot_id,
1171 started_ts=utils.utcnow(),
1172 bot_version=bot_version, 1178 bot_version=bot_version,
1173 server_versions=[utils.get_app_version()]) 1179 server_versions=[utils.get_app_version()])
1174 1180
1175 1181
1176 def yield_run_result_keys_with_dead_bot(): 1182 def yield_run_result_keys_with_dead_bot():
1177 """Yields all the TaskRunResult ndb.Key where the bot died recently. 1183 """Yields all the TaskRunResult ndb.Key where the bot died recently.
1178 1184
1179 In practice it is returning a ndb.QueryIterator but this is equivalent. 1185 In practice it is returning a ndb.QueryIterator but this is equivalent.
1180 """ 1186 """
1181 # If a bot didn't ping recently, it is considered dead. 1187 # If a bot didn't ping recently, it is considered dead.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 if tags: 1223 if tags:
1218 # Add TaskResultSummary indexes if desired. 1224 # Add TaskResultSummary indexes if desired.
1219 if sort != 'created_ts': 1225 if sort != 'created_ts':
1220 raise ValueError( 1226 raise ValueError(
1221 'Add needed indexes for sort:%s and tags if desired' % sort) 1227 'Add needed indexes for sort:%s and tags if desired' % sort)
1222 tags_filter = TaskResultSummary.tags == tags[0] 1228 tags_filter = TaskResultSummary.tags == tags[0]
1223 for tag in tags[1:]: 1229 for tag in tags[1:]:
1224 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag) 1230 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag)
1225 query = query.filter(tags_filter) 1231 query = query.filter(tags_filter)
1226 return _filter_query(TaskResultSummary, query, start, end, sort, state) 1232 return _filter_query(TaskResultSummary, query, start, end, sort, state)
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/server/task_result_test.py » ('j') | appengine/swarming/server/task_scheduler.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698