Skip to content

Commit 90673b6

Browse files
committed
Address PR review comments
1 parent 994a15c commit 90673b6

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

modal-go/invocation.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ type invocation interface {
1616
retry(retryCount uint32) error
1717
}
1818

19-
// getOutput is a function type that takes a timeout and returns a FunctionGetOutputsItem or nil, and an error.
20-
type getOutput func(timeout time.Duration) (*pb.FunctionGetOutputsItem, error)
21-
2219
// controlPlaneInvocation implements the invocation interface.
2320
type controlPlaneInvocation struct {
2421
FunctionCallId string
@@ -171,7 +168,13 @@ func (i *inputPlaneInvocation) retry(retryCount uint32) error {
171168
return nil
172169
}
173170

174-
// pollFunctionOutput repeatedly fetches the output for a given function call, waiting until a result is available or a timeout occurs.
171+
// getOutput is a function type that takes a timeout and returns a FunctionGetOutputsItem or nil, and an error.
172+
// Used by `pollForOutputs` to fetch from either the control plane or the input plane, depending on the implementation.
173+
type getOutput func(timeout time.Duration) (*pb.FunctionGetOutputsItem, error)
174+
175+
// pollFunctionOutput repeatedly tries to fetch an output using the provided `getOutput` function, and the specified
176+
// timeout value. We use a timeout value of 55 seconds if the caller does not specify a timeout value, or if the
177+
// specified timeout value is greater than 55 seconds.
175178
func pollFunctionOutput(ctx context.Context, getOutput getOutput, timeout *time.Duration) (any, error) {
176179
startTime := time.Now()
177180
pollTimeout := outputsTimeout

modal-js/src/client.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,15 @@ function authMiddleware(profile: Profile): ClientMiddleware {
3939
if (token) {
4040
modalAuthToken = token;
4141
}
42-
if (prevOnHeader) {
43-
prevOnHeader(header);
44-
}
42+
prevOnHeader?.(header);
4543
};
4644
const prevOnTrailer = options.onTrailer;
4745
options.onTrailer = (trailer) => {
4846
const token = trailer.get("x-modal-auth-token");
4947
if (token) {
5048
modalAuthToken = token;
5149
}
52-
if (prevOnTrailer) {
53-
prevOnTrailer(trailer);
54-
}
50+
prevOnTrailer?.(trailer);
5551
};
5652
return yield* call.next(call.request, options);
5753
};

modal-js/src/invocation.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ export interface Invocation {
2929
retry(retryCount: number): Promise<void>;
3030
}
3131

32-
/**
33-
* Signature of a function that fetches a single output. Used by `pollForOutputs` to fetch from either
34-
* the control plane or the input plane, depending on the implementation.
35-
*/
36-
type GetOutput = (
37-
timeoutMillis: number,
38-
) => Promise<FunctionGetOutputsItem | undefined>;
39-
4032
/**
4133
* Implementation of Invocation which sends inputs to the control plane.
4234
*/
@@ -97,19 +89,15 @@ export class ControlPlaneInvocation implements Invocation {
9789
async #getOutput(
9890
timeoutMillis: number,
9991
): Promise<FunctionGetOutputsItem | undefined> {
100-
try {
101-
const response = await client.functionGetOutputs({
102-
functionCallId: this.functionCallId,
103-
maxValues: 1,
104-
timeout: timeoutMillis / 1000, // Backend needs seconds
105-
lastEntryId: "0-0",
106-
clearOnSuccess: true,
107-
requestedAt: timeNowSeconds(),
108-
});
109-
return response.outputs ? response.outputs[0] : undefined;
110-
} catch (err) {
111-
throw new Error(`FunctionGetOutputs failed: ${err}`);
112-
}
92+
const response = await client.functionGetOutputs({
93+
functionCallId: this.functionCallId,
94+
maxValues: 1,
95+
timeout: timeoutMillis / 1000, // Backend needs seconds
96+
lastEntryId: "0-0",
97+
clearOnSuccess: true,
98+
requestedAt: timeNowSeconds(),
99+
});
100+
return response.outputs ? response.outputs[0] : undefined;
113101
}
114102

115103
async retry(retryCount: number): Promise<void> {
@@ -212,6 +200,19 @@ function timeNowSeconds() {
212200
return Date.now() / 1e3;
213201
}
214202

203+
/**
204+
* Signature of a function that fetches a single output using the given timeout. Used by `pollForOutputs` to fetch
205+
* from either the control plane or the input plane, depending on the implementation.
206+
*/
207+
type GetOutput = (
208+
timeoutMillis: number,
209+
) => Promise<FunctionGetOutputsItem | undefined>;
210+
211+
/***
212+
* Repeatedly tries to fetch an output using the provided `getOutput` function, and the specified timeout value.
213+
* We use a timeout value of 55 seconds if the caller does not specify a timeout value, or if the specified timeout
214+
* value is greater than 55 seconds.
215+
*/
215216
async function pollFunctionOutput(
216217
getOutput: GetOutput,
217218
timeout?: number, // in milliseconds

test-support/libmodal_test_support.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ def sleep(t: int) -> None:
1919
def bytelength(buf: bytes) -> int:
2020
return len(buf)
2121

22+
2223
@app.function(min_containers=1, experimental_options={"input_plane_region": "us-west"})
2324
def input_plane(s: str) -> str:
2425
return "output: " + s
2526

27+
2628
@app.cls(min_containers=1)
2729
class EchoCls:
2830
@modal.method()

0 commit comments

Comments
 (0)