Skip to content

Commit

Permalink
Update handler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Aug 14, 2023
1 parent 93dee07 commit 4f79ff0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ def generator_handler(job):
yield output


async def async_generator_handler(job):
'''
Async generator type handler.
'''
job_input = _side_effects(job['input'])

# Prepare the job output
job_output = job_input.get('mock_return', ['Hello World!'])

for output in job_output:
yield output


# ------------------------------- Side Effects ------------------------------- #
def _side_effects(job_input):
'''
Expand Down Expand Up @@ -72,6 +85,8 @@ def _side_effects(job_input):
parser = argparse.ArgumentParser()
parser.add_argument('--generator', action='store_true', default=False,
help='Starts serverless with the generator_handler')
parser.add_argument('--async_generator', action='store_true', default=False,
help='Starts serverless with the async_generator_handler')
parser.add_argument('--return_aggregate_stream', action='store_true', default=False,
help='Aggregate the stream of generator_handler and return it as a list')
args = parser.parse_args()
Expand All @@ -86,5 +101,14 @@ def _side_effects(job_input):
"return_aggregate_stream": args.return_aggregate_stream
})

elif args.async_generator:
print('Starting serverless with async_generator_handler')
print(f"return_aggregate_stream: {args.return_aggregate_stream}")

runpod.serverless.start({
"handler": async_generator_handler,
"return_aggregate_stream": args.return_aggregate_stream
})

else:
runpod.serverless.start({"handler": handler})

0 comments on commit 4f79ff0

Please sign in to comment.