Skip to content

Commit bedcdd8

Browse files
committed
Revert "fix: remove timeout_milliseconds option"
This reverts commit 31fe586.
1 parent 31fe586 commit bedcdd8

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

docs/api.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ net.http_get(
1717
-- key/value pairs to be url encoded and appended to the `url`
1818
params jsonb default '{}'::jsonb,
1919
-- key/values to be included in request headers
20-
headers jsonb default '{}'::jsonb
20+
headers jsonb default '{}'::jsonb,
21+
-- WARNING: this is currently ignored, so there is no timeout
22+
-- the maximum number of milliseconds the request may take before being cancelled
23+
timeout_milliseconds int default 1000
2124
)
2225
-- request_id reference
2326
returns bigint
@@ -59,7 +62,10 @@ net.http_post(
5962
-- key/value pairs to be url encoded and appended to the `url`
6063
params jsonb default '{}'::jsonb,
6164
-- key/values to be included in request headers
62-
headers jsonb default '{"Content-Type": "application/json"}'::jsonb
65+
headers jsonb default '{"Content-Type": "application/json"}'::jsonb,
66+
-- WARNING: this is currently ignored, so there is no timeout
67+
-- the maximum number of milliseconds the request may take before being cancelled
68+
timeout_milliseconds int default 1000
6369
)
6470
-- request_id reference
6571
returns bigint

sql/pg_net--0.1.sql

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ create table net.http_request_queue(
1414
url text not null,
1515
headers jsonb not null,
1616
body bytea,
17+
-- TODO: respect this
18+
timeout_milliseconds int not null,
1719
created timestamptz not null default now()
1820
);
1921

@@ -91,7 +93,9 @@ create or replace function net.http_get(
9193
-- key/value pairs to be url encoded and appended to the `url`
9294
params jsonb default '{}'::jsonb,
9395
-- key/values to be included in request headers
94-
headers jsonb default '{}'::jsonb
96+
headers jsonb default '{}'::jsonb,
97+
-- the maximum number of milliseconds the request may take before being cancelled
98+
timeout_milliseconds int default 1000
9599
)
96100
-- request_id reference
97101
returns bigint
@@ -109,11 +113,12 @@ begin
109113
from jsonb_each_text(params);
110114

111115
-- Add to the request queue
112-
insert into net.http_request_queue(method, url, headers)
116+
insert into net.http_request_queue(method, url, headers, timeout_milliseconds)
113117
values (
114118
'GET',
115119
net._encode_url_with_params_array(url, params_array),
116-
headers
120+
headers,
121+
timeout_milliseconds
117122
)
118123
returning id
119124
into request_id;
@@ -132,7 +137,9 @@ create or replace function net.http_post(
132137
-- key/value pairs to be url encoded and appended to the `url`
133138
params jsonb default '{}'::jsonb,
134139
-- key/values to be included in request headers
135-
headers jsonb default '{"Content-Type": "application/json"}'::jsonb
140+
headers jsonb default '{"Content-Type": "application/json"}'::jsonb,
141+
-- the maximum number of milliseconds the request may take before being cancelled
142+
timeout_milliseconds int DEFAULT 1000
136143
)
137144
-- request_id reference
138145
returns bigint
@@ -180,12 +187,13 @@ begin
180187
jsonb_each_text(params);
181188

182189
-- Add to the request queue
183-
insert into net.http_request_queue(method, url, headers, body)
190+
insert into net.http_request_queue(method, url, headers, body, timeout_milliseconds)
184191
values (
185192
'POST',
186193
net._encode_url_with_params_array(url, params_array),
187194
headers,
188-
body::text::bytea
195+
body::text::bytea,
196+
timeout_milliseconds
189197
)
190198
returning id
191199
into request_id;

0 commit comments

Comments
 (0)