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

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: Add test case 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
« no previous file with comments | « no previous file | appengine/swarming/server/task_result_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 1169
1163 The caller must save it in the DB. 1170 The caller must save it in the DB.
1164 """ 1171 """
1165 assert isinstance(request, task_request.TaskRequest) 1172 assert isinstance(request, task_request.TaskRequest)
1166 summary_key = task_pack.request_key_to_result_summary_key(request.key) 1173 summary_key = task_pack.request_key_to_result_summary_key(request.key)
1167 return TaskRunResult( 1174 return TaskRunResult(
1168 key=task_pack.result_summary_key_to_run_result_key( 1175 key=task_pack.result_summary_key_to_run_result_key(
1169 summary_key, try_number), 1176 summary_key, try_number),
1170 bot_dimensions=bot_dimensions, 1177 bot_dimensions=bot_dimensions,
1171 bot_id=bot_id, 1178 bot_id=bot_id,
1172 started_ts=utils.utcnow(),
1173 bot_version=bot_version, 1179 bot_version=bot_version,
1174 server_versions=[utils.get_app_version()]) 1180 server_versions=[utils.get_app_version()])
1175 1181
1176 1182
1177 def yield_run_result_keys_with_dead_bot(): 1183 def yield_run_result_keys_with_dead_bot():
1178 """Yields all the TaskRunResult ndb.Key where the bot died recently. 1184 """Yields all the TaskRunResult ndb.Key where the bot died recently.
1179 1185
1180 In practice it is returning a ndb.QueryIterator but this is equivalent. 1186 In practice it is returning a ndb.QueryIterator but this is equivalent.
1181 """ 1187 """
1182 # If a bot didn't ping recently, it is considered dead. 1188 # If a bot didn't ping recently, it is considered dead.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 if tags: 1224 if tags:
1219 # Add TaskResultSummary indexes if desired. 1225 # Add TaskResultSummary indexes if desired.
1220 if sort != 'created_ts': 1226 if sort != 'created_ts':
1221 raise ValueError( 1227 raise ValueError(
1222 'Add needed indexes for sort:%s and tags if desired' % sort) 1228 'Add needed indexes for sort:%s and tags if desired' % sort)
1223 tags_filter = TaskResultSummary.tags == tags[0] 1229 tags_filter = TaskResultSummary.tags == tags[0]
1224 for tag in tags[1:]: 1230 for tag in tags[1:]:
1225 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag) 1231 tags_filter = ndb.AND(tags_filter, TaskResultSummary.tags == tag)
1226 query = query.filter(tags_filter) 1232 query = query.filter(tags_filter)
1227 return _filter_query(TaskResultSummary, query, start, end, sort, state) 1233 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698