| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """Commit queue executable. | 5 """Commit queue executable. |
| 6 | 6 |
| 7 Reuse Rietveld and the Chromium Try Server to process and automatically commit | 7 Reuse Rietveld and the Chromium Try Server to process and automatically commit |
| 8 patches. | 8 patches. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 pc.context.checkout = FakeCheckout() | 260 pc.context.checkout = FakeCheckout() |
| 261 else: | 261 else: |
| 262 print 'Using read-only checkout' | 262 print 'Using read-only checkout' |
| 263 pc.context.checkout = checkout.ReadOnlyCheckout(pc.context.checkout) | 263 pc.context.checkout = checkout.ReadOnlyCheckout(pc.context.checkout) |
| 264 # Save pushed events on disk. | 264 # Save pushed events on disk. |
| 265 print 'Using read-only chromium-status interface' | 265 print 'Using read-only chromium-status interface' |
| 266 pc.context.status = async_push.AsyncPushStore() | 266 pc.context.status = async_push.AsyncPushStore() |
| 267 | 267 |
| 268 db_path = os.path.join(work_dir, pc.context.checkout.project_name + '.json') | 268 db_path = os.path.join(work_dir, pc.context.checkout.project_name + '.json') |
| 269 if os.path.isfile(db_path): | 269 if os.path.isfile(db_path): |
| 270 try: | 270 # Do not load state, and in fact remove it when seen. This will hopefully |
| 271 pc.load(db_path) | 271 # help avoid issues with CQ committing changes without verification. |
| 272 except ValueError: | 272 os.remove(db_path) |
| 273 os.remove(db_path) | |
| 274 | 273 |
| 275 sig_handler.installHandlers( | 274 sig_handler.installHandlers( |
| 276 signal.SIGINT, | 275 signal.SIGINT, |
| 277 signal.SIGHUP | 276 signal.SIGHUP |
| 278 ) | 277 ) |
| 279 | 278 |
| 280 # Sync every 5 minutes. | 279 # Sync every 5 minutes. |
| 281 SYNC_DELAY = 5*60 | 280 SYNC_DELAY = 5*60 |
| 282 try: | 281 try: |
| 283 if options.query_only: | 282 if options.query_only: |
| 284 pc.look_for_new_pending_commit() | 283 pc.look_for_new_pending_commit() |
| 285 pc.update_status() | 284 pc.update_status() |
| 286 print(str(pc.queue)) | 285 print(str(pc.queue)) |
| 287 return 0 | 286 return 0 |
| 288 | 287 |
| 289 now = time.time() | 288 now = time.time() |
| 290 next_loop = now + options.poll_interval | 289 next_loop = now + options.poll_interval |
| 291 # First sync is on second loop. | 290 # First sync is on second loop. |
| 292 next_sync = now + options.poll_interval * 2 | 291 next_sync = now + options.poll_interval * 2 |
| 293 while True: | 292 while True: |
| 294 # In theory, we would gain in performance to parallelize these tasks. In | 293 # In theory, we would gain in performance to parallelize these tasks. In |
| 295 # practice I'm not sure it matters. | 294 # practice I'm not sure it matters. |
| 296 pc.look_for_new_pending_commit() | 295 pc.look_for_new_pending_commit() |
| 297 pc.process_new_pending_commit() | 296 pc.process_new_pending_commit() |
| 298 pc.update_status() | 297 pc.update_status() |
| 299 pc.scan_results() | 298 pc.scan_results() |
| 300 if sig_handler.getTriggeredSignals(): | 299 if sig_handler.getTriggeredSignals(): |
| 301 raise KeyboardInterrupt() | 300 raise KeyboardInterrupt() |
| 302 # Save the db at each loop. The db can easily be in the 1mb range so | 301 # We'd save the state here but its suspected to cause CQ to land changes |
| 303 # it's slowing down the CQ a tad but it in the 100ms range even for that | 302 # without verification. |
| 304 # size. | |
| 305 pc.save(db_path) | |
| 306 | 303 |
| 307 # More than a second to wait and due to sync. | 304 # More than a second to wait and due to sync. |
| 308 now = time.time() | 305 now = time.time() |
| 309 if (next_loop - now) >= 1 and (next_sync - now) <= 0: | 306 if (next_loop - now) >= 1 and (next_sync - now) <= 0: |
| 310 if sys.stdout.isatty(): | 307 if sys.stdout.isatty(): |
| 311 sys.stdout.write('Syncing while waiting \r') | 308 sys.stdout.write('Syncing while waiting \r') |
| 312 sys.stdout.flush() | 309 sys.stdout.flush() |
| 313 try: | 310 try: |
| 314 pc.context.checkout.prepare(None) | 311 pc.context.checkout.prepare(None) |
| 315 except subprocess2.CalledProcessError as e: | 312 except subprocess2.CalledProcessError as e: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 330 if sys.stdout.isatty(): | 327 if sys.stdout.isatty(): |
| 331 sys.stdout.write('Sleeping for %1.1f seconds \r' % delay) | 328 sys.stdout.write('Sleeping for %1.1f seconds \r' % delay) |
| 332 sys.stdout.flush() | 329 sys.stdout.flush() |
| 333 time.sleep(min(delay, 0.1)) | 330 time.sleep(min(delay, 0.1)) |
| 334 now = time.time() | 331 now = time.time() |
| 335 if sys.stdout.isatty(): | 332 if sys.stdout.isatty(): |
| 336 sys.stdout.write('Running (please do not interrupt) \r') | 333 sys.stdout.write('Running (please do not interrupt) \r') |
| 337 sys.stdout.flush() | 334 sys.stdout.flush() |
| 338 next_loop = time.time() + options.poll_interval | 335 next_loop = time.time() + options.poll_interval |
| 339 finally: | 336 finally: |
| 340 print >> sys.stderr, 'Saving db... ' | 337 # We'd save the state here but its suspected to cause CQ to land changes |
| 341 pc.save(db_path) | 338 # without verification. |
| 342 pc.close() | 339 pc.close() |
| 343 print >> sys.stderr, 'Done! ' | |
| 344 except KeyboardInterrupt as e: | 340 except KeyboardInterrupt as e: |
| 345 print 'Bye bye' | 341 print 'Bye bye' |
| 346 # 23 is an arbitrary value to signal loop.sh that it must stop looping. | 342 # 23 is an arbitrary value to signal loop.sh that it must stop looping. |
| 347 return 23 | 343 return 23 |
| 348 except SystemExit as e: | 344 except SystemExit as e: |
| 349 traceback.print_exc() | 345 traceback.print_exc() |
| 350 print >> sys.stderr, ('Tried to exit: %s', e) | 346 print >> sys.stderr, ('Tried to exit: %s', e) |
| 351 return e.code | 347 return e.code |
| 352 except errors.ConfigurationError as e: | 348 except errors.ConfigurationError as e: |
| 353 parser.error(str(e)) | 349 parser.error(str(e)) |
| 354 return 1 | 350 return 1 |
| 355 return 0 | 351 return 0 |
| 356 | 352 |
| 357 | 353 |
| 358 if __name__ == '__main__': | 354 if __name__ == '__main__': |
| 359 fix_encoding.fix_encoding() | 355 fix_encoding.fix_encoding() |
| 360 sys.exit(main()) | 356 sys.exit(main()) |
| OLD | NEW |