Skip to content

Commit cfeca6c

Browse files
author
Lukas Wingerberg
committed
introduce exit code propagation
1 parent 1fc224b commit cfeca6c

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

client/ffmpeg.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ message CommandRequest {
1313
message CommandResponse {
1414
string output = 1;
1515
int32 exit_code = 2;
16-
string stream = 3; // Added field to indicate stream type
16+
string stream = 3; // "stdout", "stderr", or "exit_code"
1717
}

client/grpc-ffmpeg.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ async def run_command(command, use_ssl):
2929
else:
3030
channel = grpc.aio.insecure_channel(target)
3131

32+
exit_code = 0 # Default exit code
33+
3234
async with channel:
3335
stub = ffmpeg_pb2_grpc.FFmpegServiceStub(channel)
3436
request = ffmpeg_pb2.CommandRequest(command=command)
3537
async for response in stub.ExecuteCommand(request):
36-
if response.output:
37-
if response.stream:
38-
if response.stream == "STDOUT":
39-
sys.stdout.write(f"{response.output}\n") # Write to stdout
40-
else:
41-
sys.stderr.write(f"{response.stream}: {response.output}\n") # Write to stderr with prefix
42-
else:
43-
print(response.output, end="")
38+
if response.output_type == "stdout":
39+
sys.stdout.write(f"{response.output}")
40+
elif response.output_type == "stderr":
41+
sys.stderr.write(f"{response.output}")
42+
elif response.output_type == "exit_code":
43+
exit_code = response.exit_code
44+
45+
return exit_code
4446

4547
def handle_quoted_arguments(command_args):
4648
"""
@@ -101,5 +103,6 @@ def handle_quoted_arguments(command_args):
101103
# Convert the list to a single command string
102104
command_str = ' '.join(command)
103105

104-
# Run the command
105-
asyncio.run(run_command(command_str, USE_SSL))
106+
# Run the command and handle exit code
107+
exit_code = asyncio.run(run_command(command_str, USE_SSL))
108+
sys.exit(exit_code)

proto/ffmpeg.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ message CommandRequest {
1313
message CommandResponse {
1414
string output = 1;
1515
int32 exit_code = 2;
16-
string stream = 3; // Added field to indicate stream type
16+
string stream = 3; // "stdout", "stderr", or "exit_code"
1717
}

server/grpc-ffmpeg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def read_stream(stream, response_type, stream_name):
9191

9292
await process.wait()
9393
exit_code = process.returncode
94-
yield ffmpeg_pb2.CommandResponse(exit_code=exit_code)
94+
yield ffmpeg_pb2.CommandResponse(exit_code=exit_code, stream_name="exit_code")
9595

9696
async def health_check(self):
9797
logger.info("Running initial health check...")

0 commit comments

Comments
 (0)