Repository navigation
Add Modal Serverless Worker integration - #1970
harish-narayanappa-10 wants to merge 6 commits into
Conversation
|
|
| """Run Temporal workers inside Modal Functions. | ||
|
|
||
| The integration owns the worker lifecycle within one already-running Modal | ||
| Function invocation. Authentication and invocation between a controller and |
There was a problem hiding this comment.
Can remove "Authentication and invocation ..."
There was a problem hiding this comment.
We don't need to call out things we didn't do
There was a problem hiding this comment.
The LLMs are pretty bad at these types of comments - can you go through the comments in the PR in general and make sure it isn't adding any text that a user wouldn't expect to see or that is unrelated to the plugins purpose
There was a problem hiding this comment.
addressed/reviewed as suggested
| config.execution_timeout = WORKER_EXECUTION_TIMEOUT | ||
|
|
||
|
|
||
| @app.function(timeout=int(MODAL_FUNCTION_TIMEOUT.total_seconds())) |
There was a problem hiding this comment.
Can you add a simple workflow and activity to all the example code?
|
|
||
| Call this from a top-level async function decorated with | ||
| ``@app.function``. A fresh Temporal client and worker are created for every | ||
| invocation. The worker polls until its execution budget approaches the |
There was a problem hiding this comment.
Can you talk about this behavior in the main README example? As a customer I think I'd want to know very clearly what this is doing - stops polling at time T, then allows X time for finishing activities etc.
There was a problem hiding this comment.
added lifecycle timeline to the README showing setup, when polling stops, Modal deadline etc
|
|
||
| WORKER_EXECUTION_TIMEOUT = timedelta(minutes=2) | ||
| MODAL_FUNCTION_TIMEOUT = ( | ||
| WORKER_EXECUTION_TIMEOUT + MIN_FUNCTION_TIMEOUT_HEADROOM |
There was a problem hiding this comment.
Why expose this to the customer? If I'm a customer I just want to simply state that my functions run for a maximum of 5 minutes. But with this approach they need to do math to figure out how long their functions run.
Can't we just set the @app.function timeout to 5 minutes, set the modal_function_timeout to 5 minutes, and then let the internal run_worker code subtract the MIN_FUNCTION_TIMEOUT_HEADROOM
There was a problem hiding this comment.
Updated as suggested. @app.function(timeout=...) and modal_function_timeout now use the same value
| base_connect_config: ClientConnectConfig = {**profile.to_client_connect_config()} | ||
|
|
||
| base_worker_config: WorkerConfig = {} | ||
| apply_modal_worker_defaults(base_worker_config) |
There was a problem hiding this comment.
This sets graceful_shutdown_timeout to 5s (DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT) and then when you compute graceful_timeout on line 240 it always uses this 5s value not the user supplied configuration value. So shutdown_deadline_buffer is always 7s
There was a problem hiding this comment.
Polling stops with 7 seconds of budget left no matter what they set for graceful_shutdown_timeout
There was a problem hiding this comment.
Fixed. The default shutdown buffer is now calculated after configure from the final graceful_shutdown_timeout, plus two seconds for shutdown hooks
| config.worker_config["activities"] = [my_activity] | ||
| config.execution_timeout = WORKER_EXECUTION_TIMEOUT | ||
|
|
||
|
|
There was a problem hiding this comment.
If you set this:
@app.function(timeout=900) # 15-minute container
async def temporal_worker():
await run_worker(VERSION, configure,
modal_function_timeout=timedelta(minutes=15))
execution_timeout is still 5 minutes if you don't set it in the config
There was a problem hiding this comment.
Fixed. execution_timeout now defaults to modal_function_timeout minus the internal 15-second headroom
tconley1428
left a comment
There was a problem hiding this comment.
Discussing offline a final location for this code.
Summary
temporalio.contrib.modal.workerfor running a versioned Temporal Worker during one Modal Function invocationTesting
uv run pytest tests/contrib/modal/worker/test_modal_worker.pytemporalio/contrib/modalandtests/contrib/modalpoe formatpoe gen-docs