|
6 | 6 | import shutil |
7 | 7 | import subprocess |
8 | 8 | import sys |
| 9 | +import time |
9 | 10 | import termios |
10 | 11 | import tty |
11 | 12 | from datetime import datetime |
|
23 | 24 | _TAIL_BYTES = 256 * 1024 |
24 | 25 | _TAIL_MAX_BYTES = 4 * 1024 * 1024 |
25 | 26 | _TAIL_MIN_LINES = 200 |
| 27 | +_PROJECT_LOOP_SLEEP = 30 |
26 | 28 | _ROLL_OUT_PREFIX = "rollout-" |
27 | 29 | _SCIENCE_TEMPLATE = ( |
28 | 30 | "Good afternoon! We have a fun task today - take a good look around this repo " |
@@ -1128,6 +1130,11 @@ def main(argv=None): |
1128 | 1130 | action="store_true", |
1129 | 1131 | help="Suppress progress output during verification.", |
1130 | 1132 | ) |
| 1133 | + task_parser.add_argument( |
| 1134 | + "--loop", |
| 1135 | + action="store_true", |
| 1136 | + help="With -p, keep taking tasks and wait when none are available.", |
| 1137 | + ) |
1131 | 1138 |
|
1132 | 1139 | ralph_parser = subparsers.add_parser( |
1133 | 1140 | "ralph", |
@@ -1363,24 +1370,49 @@ def main(argv=None): |
1363 | 1370 | raise SystemExit("--name is required with --project.") |
1364 | 1371 | if not args.task_args: |
1365 | 1372 | raise SystemExit("task --project requires one or more task files.") |
1366 | | - try: |
1367 | | - from .gh_integration import GhTaskRunner |
1368 | | - except ImportError as exc: |
1369 | | - raise SystemExit("gh-task is required for --project. Install it with pip.") from exc |
1370 | | - |
1371 | | - task_runner = GhTaskRunner( |
1372 | | - args.project, |
1373 | | - args.name, |
1374 | | - args.task_args, |
1375 | | - args.status, |
1376 | | - args.cwd, |
1377 | | - args.yolo, |
1378 | | - args.flags, |
1379 | | - ) |
1380 | | - result = task_runner(progress=not args.quiet) |
1381 | | - if not result.success: |
1382 | | - raise SystemExit(1) |
1383 | | - return |
| 1373 | + from .gh_integration import GhTaskRunner |
| 1374 | + from gh_task.errors import TakeError |
| 1375 | + |
| 1376 | + if args.loop: |
| 1377 | + while True: |
| 1378 | + try: |
| 1379 | + task_runner = GhTaskRunner( |
| 1380 | + args.project, |
| 1381 | + args.name, |
| 1382 | + args.task_args, |
| 1383 | + args.status, |
| 1384 | + args.cwd, |
| 1385 | + args.yolo, |
| 1386 | + args.flags, |
| 1387 | + ) |
| 1388 | + except TakeError as exc: |
| 1389 | + print(str(exc), file=sys.stderr) |
| 1390 | + print( |
| 1391 | + f"Waiting {_PROJECT_LOOP_SLEEP}s for new tasks...", |
| 1392 | + file=sys.stderr, |
| 1393 | + ) |
| 1394 | + time.sleep(_PROJECT_LOOP_SLEEP) |
| 1395 | + continue |
| 1396 | + result = task_runner(progress=not args.quiet) |
| 1397 | + if not result.success: |
| 1398 | + raise SystemExit(1) |
| 1399 | + else: |
| 1400 | + try: |
| 1401 | + task_runner = GhTaskRunner( |
| 1402 | + args.project, |
| 1403 | + args.name, |
| 1404 | + args.task_args, |
| 1405 | + args.status, |
| 1406 | + args.cwd, |
| 1407 | + args.yolo, |
| 1408 | + args.flags, |
| 1409 | + ) |
| 1410 | + except TakeError as exc: |
| 1411 | + raise SystemExit(str(exc)) from None |
| 1412 | + result = task_runner(progress=not args.quiet) |
| 1413 | + if not result.success: |
| 1414 | + raise SystemExit(1) |
| 1415 | + return |
1384 | 1416 |
|
1385 | 1417 | if args.command == "task" and args.task_file: |
1386 | 1418 | if args.task_args: |
@@ -1449,6 +1481,8 @@ def main(argv=None): |
1449 | 1481 | if args.command == "task": |
1450 | 1482 | if args.project: |
1451 | 1483 | raise SystemExit("task --project already handled earlier.") |
| 1484 | + if args.loop: |
| 1485 | + raise SystemExit("--loop is only supported with -p.") |
1452 | 1486 | if args.item is not None: |
1453 | 1487 | raise SystemExit("--item is only supported with -f.") |
1454 | 1488 | if args.max_iterations is None: |
|
0 commit comments