OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import time | 8 import time |
9 | 9 |
10 import flask | 10 import flask |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 task_tag = task.BackendParams()['tag'] | 164 task_tag = task.BackendParams()['tag'] |
165 | 165 |
166 # Create the instance template if required. | 166 # Create the instance template if required. |
167 if not CreateInstanceTemplate(task): | 167 if not CreateInstanceTemplate(task): |
168 return Render('Template creation failed.', memory_logs) | 168 return Render('Template creation failed.', memory_logs) |
169 | 169 |
170 # Split the task in smaller tasks. | 170 # Split the task in smaller tasks. |
171 sub_tasks = [] | 171 sub_tasks = [] |
172 task_url = None | 172 task_url = None |
173 if task.Action() == 'trace': | 173 if task.Action() == 'trace' or task.Action == 'report': |
174 bucket = task.BackendParams().get('storage_bucket') | 174 bucket = task.BackendParams().get('storage_bucket') |
175 if bucket: | 175 if bucket: |
176 task_url = 'https://console.cloud.google.com/storage/' + bucket | 176 task_url = 'https://console.cloud.google.com/storage/' + bucket |
177 sub_tasks = SplitTraceTask(task) | 177 sub_tasks = SplitTaskUrls(task) |
178 else: | 178 else: |
179 error_string = 'Unsupported action: %s.' % task.Action() | 179 error_string = 'Unsupported action: %s.' % task.Action() |
180 clovis_logger.error(error_string) | 180 clovis_logger.error(error_string) |
181 return Render(error_string, memory_logs) | 181 return Render(error_string, memory_logs) |
182 | 182 |
183 if not EnqueueTasks(sub_tasks, task_tag): | 183 if not EnqueueTasks(sub_tasks, task_tag): |
184 return Render('Task creation failed.', memory_logs) | 184 return Render('Task creation failed.', memory_logs) |
185 | 185 |
186 # Start the instances if required. | 186 # Start the instances if required. |
187 if not CreateInstances(task): | 187 if not CreateInstances(task): |
188 return Render('Instance creation failed.', memory_logs) | 188 return Render('Instance creation failed.', memory_logs) |
189 | 189 |
190 # Start polling the progress. | 190 # Start polling the progress. |
191 clovis_logger.info('Creating worker polling task.') | 191 clovis_logger.info('Creating worker polling task.') |
192 first_poll_delay_minutes = 10 | 192 first_poll_delay_minutes = 10 |
193 timeout_hours = task.BackendParams().get('timeout_hours', 5) | 193 timeout_hours = task.BackendParams().get('timeout_hours', 5) |
194 user_email = email_helper.GetUserEmail() | 194 user_email = email_helper.GetUserEmail() |
195 deferred.defer(PollWorkers, task_tag, time.time(), timeout_hours, user_email, | 195 deferred.defer(PollWorkers, task_tag, time.time(), timeout_hours, user_email, |
196 task_url, _countdown=(60 * first_poll_delay_minutes)) | 196 task_url, _countdown=(60 * first_poll_delay_minutes)) |
197 | 197 |
198 return Render(flask.Markup( | 198 return Render(flask.Markup( |
199 'Success!<br>Your task %s has started.<br>' | 199 'Success!<br>Your task %s has started.<br>' |
200 'You will be notified at %s when completed.') % (task_tag, user_email), | 200 'You will be notified at %s when completed.') % (task_tag, user_email), |
201 memory_logs) | 201 memory_logs) |
202 | 202 |
203 | 203 |
204 def SplitTraceTask(task): | 204 def SplitTaskUrls(task): |
205 """Splits a tracing task with potentially many URLs into several tracing tasks | 205 """Splits a task with potentially many URLs into several tasks with few URLs. |
206 with few URLs. | |
207 """ | 206 """ |
208 clovis_logger.debug('Splitting trace task.') | 207 clovis_logger.debug('Splitting trace task.') |
209 action_params = task.ActionParams() | 208 action_params = task.ActionParams() |
210 urls = action_params['urls'] | 209 urls = action_params['urls'] |
211 | 210 |
212 # Split the task in smaller tasks with fewer URLs each. | 211 # Split the task in smaller tasks with fewer URLs each. |
213 urls_per_task = 1 | 212 urls_per_task = 1 |
214 sub_tasks = [] | 213 sub_tasks = [] |
215 for i in range(0, len(urls), urls_per_task): | 214 for i in range(0, len(urls), urls_per_task): |
216 sub_task_params = action_params.copy() | 215 sub_task_params = action_params.copy() |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 @app.errorhandler(404) | 267 @app.errorhandler(404) |
269 def PageNotFound(e): # pylint: disable=unused-argument | 268 def PageNotFound(e): # pylint: disable=unused-argument |
270 """Return a custom 404 error.""" | 269 """Return a custom 404 error.""" |
271 return 'Sorry, Nothing at this URL.', 404 | 270 return 'Sorry, Nothing at this URL.', 404 |
272 | 271 |
273 | 272 |
274 @app.errorhandler(500) | 273 @app.errorhandler(500) |
275 def ApplicationError(e): | 274 def ApplicationError(e): |
276 """Return a custom 500 error.""" | 275 """Return a custom 500 error.""" |
277 return 'Sorry, unexpected error: {}'.format(e), 499 | 276 return 'Sorry, unexpected error: {}'.format(e), 499 |
OLD | NEW |