You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `wait.forHttpCallback()` function gives you a callback URL, and then pauses the run until that callback is hit with a POST request. This is most commonly used with 3rd party APIs that take a long time and that accept a callback (or webhook) URL.
8
+
The `wait.createHttpCallback()` function gives you a callback URL and returns a token representing the waitpoint. You should call a third-party API and provide it with the callback URL so they can notify you when their work is done.
9
9
10
-
When the callback URL is requested the run will continue where it left off with the body of the request as the output available for you to use.
10
+
Then you can use `wait.forToken()` to pause the run until the callback URL is hit with a `POST`request.
11
11
12
12
<UpgradeToV4Note />
13
13
14
14
## Usage
15
15
16
-
In this example we create an image using Replicate. Their API accepts a "webhook", which is a callback.
16
+
In this example we create an image using Replicate. Their API accepts a “webhook”, which is an HTTP POST callback.
If set to true, this will cause the waitpoint to release the current run from the queue's concurrency.
109
-
110
-
This is useful if you want to allow other runs to execute while waiting
111
-
112
-
Note: It's possible that this run will not be able to resume when the waitpoint is complete if this is set to true.
113
-
It will go back in the queue and will resume once concurrency becomes available.
114
-
115
-
The default is `false`.
116
-
117
-
</ParamField>
118
-
119
103
### returns
120
104
121
-
The `forHttpCallback` function returns a result object with the following properties:
105
+
`wait.createHttpCallback()`returns an object with:
122
106
123
-
<ParamFieldquery="ok"type="boolean">
107
+
<ParamFieldquery="token"type="object">
124
108
Whether the token was completed successfully.
125
-
</ParamField>
126
109
127
-
<ParamFieldquery="output"type="any">
128
-
If `ok` is `true`, this will be the output of the token.
110
+
<Expandabletitle="properties"defaultOpen={true}>
111
+
<ParamFieldquery="id"type="string">
112
+
The ID of the token. Starts with `waitpoint_`.
113
+
</ParamField>
114
+
<ParamFieldquery="isCached"type="boolean">
115
+
Whether the token is cached. Will return true if the token was created with an idempotency key and
116
+
the same idempotency key was used again.
117
+
</ParamField>
118
+
119
+
<ParamFieldquery="url"type="string">
120
+
The URL that was created for the waitpoint. Call this via an HTTP POST request to complete the
121
+
waitpoint and continue the run with the JSON body of the request.
122
+
</ParamField>
123
+
124
+
</Expandable>
129
125
</ParamField>
130
126
131
-
<ParamFieldquery="error"type="Error">
132
-
If `ok` is `false`, this will be the error that occurred. The only error that can occur is a
133
-
timeout error.
127
+
<ParamFieldquery="data"type="object">
128
+
If you returned anything from the function, it will be here.
134
129
</ParamField>
135
130
136
-
### unwrap() returns
137
-
138
-
If you use the `unwrap()` method, it will just return the output of the token. If an error occurs it will throw an error.
139
-
140
-
## The format of the callback request
131
+
## Calling the callback URL yourself
141
132
142
-
If you want to offload work to one of your own services you will need to do the callback request yourself.
133
+
`wait.createHttpCallback()` returns a unique one-time-use URL.
143
134
144
-
The `wait.forHttpCallback()` function gives you a unique one-time use URL. You should do a `POST` request to this URL with a text body that is JSONparseable.
135
+
You should do a `POST` request to this URL with a text body that is JSON-parseable. If there's no body it will use an empty object `{}`.
0 commit comments