|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +import asyncio |
3 | 4 | import os
|
4 | 5 | import signal
|
5 | 6 | import subprocess
|
@@ -32,21 +33,22 @@ def die(signal: int, frame: FrameType) -> None:
|
32 | 33 | sys.exit(0)
|
33 | 34 |
|
34 | 35 | if options.forward_class_messages and not options.noshard:
|
35 |
| - # Needed to get access to zephyr.lib.parallel |
36 |
| - sys.path.append("/home/zulip/zulip") |
37 | 36 | if options.on_startup_command is not None:
|
38 | 37 | subprocess.call([options.on_startup_command])
|
39 |
| - from zerver.lib.parallel import run_parallel |
40 | 38 |
|
41 | 39 | print("Starting parallel zephyr class mirroring bot")
|
42 |
| - jobs = list("0123456789abcdef") |
| 40 | + shards = list("0123456789abcdef") |
43 | 41 |
|
44 |
| - def run_job(shard: str) -> int: |
45 |
| - subprocess.call(args + [f"--shard={shard}"]) |
46 |
| - return 0 |
| 42 | + async def run_shard(shard: str) -> int: |
| 43 | + process = await asyncio.create_subprocess_exec(*args, f"--shard={shard}") |
| 44 | + return await process.wait() |
47 | 45 |
|
48 |
| - for (status, job) in run_parallel(run_job, jobs, threads=16): |
49 |
| - print("A mirroring shard died!") |
| 46 | + async def run_shards(): |
| 47 | + for coro in asyncio.as_completed(map(run_shard, shards)): |
| 48 | + await coro |
| 49 | + print("A mirroring shard died!") |
| 50 | + |
| 51 | + asyncio.run(run_shards()) |
50 | 52 | sys.exit(0)
|
51 | 53 |
|
52 | 54 | backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
|
|
0 commit comments