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

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

Issue 2856733002: swarming: add transaction_id to tasks.new request
Patch Set: nits Created 3 years, 7 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 # coding: utf-8 1 # coding: utf-8
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Packing and unpacking of ndb.Key. 6 """Packing and unpacking of ndb.Key.
7 7
8 End users are only given packed keys, which permits to not expose internal 8 End users are only given packed keys, which permits to not expose internal
9 schema details to the user. 9 schema details to the user.
10 """ 10 """
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 """Returns the PerformanceStats ndb.Key for this TaskRunResult.key. 71 """Returns the PerformanceStats ndb.Key for this TaskRunResult.key.
72 """ 72 """
73 assert run_result_key.kind() == 'TaskRunResult', run_result_key 73 assert run_result_key.kind() == 'TaskRunResult', run_result_key
74 return ndb.Key('PerformanceStats', 1, parent=run_result_key) 74 return ndb.Key('PerformanceStats', 1, parent=run_result_key)
75 75
76 76
77 ### Packing and unpacking. 77 ### Packing and unpacking.
78 78
79 79
80 def get_request_and_result_keys(task_id): 80 def get_request_and_result_keys(task_id):
81 """Provides the key and TaskRequest corresponding to a task ID. 81 """Provides request and result keys corresponding to a task ID.
82 82
83 Returns: 83 Returns:
84 tuple(request_key, result_key): ndb.Key that yield TaskRequest and either 84 tuple(request_key, result_key): ndb.Key that yield TaskRequest and either
85 (TaskRunResult or TaskResultSummay). 85 (TaskRunResult or TaskResultSummary).
86 """ 86 """
87 try: 87 try:
88 key = unpack_result_summary_key(task_id) 88 key = unpack_result_summary_key(task_id)
89 request_key = result_summary_key_to_request_key(key) 89 request_key = result_summary_key_to_request_key(key)
90 except ValueError: 90 except ValueError:
91 key = unpack_run_result_key(task_id) 91 key = unpack_run_result_key(task_id)
92 request_key = result_summary_key_to_request_key( 92 request_key = result_summary_key_to_request_key(
93 run_result_key_to_result_summary_key(key)) 93 run_result_key_to_result_summary_key(key))
94 return request_key, key 94 return request_key, key
95 95
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 """Returns the TaskRunResult ndb.Key from a packed key. 164 """Returns the TaskRunResult ndb.Key from a packed key.
165 165
166 The expected format of |packed_key| is %x. 166 The expected format of |packed_key| is %x.
167 """ 167 """
168 request_key = unpack_request_key(packed_key[:-1]) 168 request_key = unpack_request_key(packed_key[:-1])
169 run_id = int(packed_key[-1], 16) 169 run_id = int(packed_key[-1], 16)
170 if not run_id: 170 if not run_id:
171 raise ValueError('Can\'t reference to the overall task result.') 171 raise ValueError('Can\'t reference to the overall task result.')
172 result_summary_key = request_key_to_result_summary_key(request_key) 172 result_summary_key = request_key_to_result_summary_key(request_key)
173 return result_summary_key_to_run_result_key(result_summary_key, run_id) 173 return result_summary_key_to_run_result_key(result_summary_key, run_id)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698