diff --git a/docs/api.md b/docs/api.md index cb3f9df..f854dba 100644 --- a/docs/api.md +++ b/docs/api.md @@ -17,7 +17,10 @@ net.http_get( -- key/value pairs to be url encoded and appended to the `url` params jsonb default '{}'::jsonb, -- key/values to be included in request headers - headers jsonb default '{}'::jsonb + headers jsonb default '{}'::jsonb, + -- WARNING: this is currently ignored, so there is no timeout + -- the maximum number of milliseconds the request may take before being cancelled + timeout_milliseconds int default 1000 ) -- request_id reference returns bigint @@ -59,7 +62,10 @@ net.http_post( -- key/value pairs to be url encoded and appended to the `url` params jsonb default '{}'::jsonb, -- key/values to be included in request headers - headers jsonb default '{"Content-Type": "application/json"}'::jsonb + headers jsonb default '{"Content-Type": "application/json"}'::jsonb, + -- WARNING: this is currently ignored, so there is no timeout + -- the maximum number of milliseconds the request may take before being cancelled + timeout_milliseconds int default 1000 ) -- request_id reference returns bigint diff --git a/sql/pg_net--0.1.sql b/sql/pg_net--0.1.sql index 859e292..b05fb8a 100644 --- a/sql/pg_net--0.1.sql +++ b/sql/pg_net--0.1.sql @@ -14,6 +14,8 @@ create table net.http_request_queue( url text not null, headers jsonb not null, body bytea, + -- TODO: respect this + timeout_milliseconds int not null, created timestamptz not null default now() ); @@ -91,7 +93,9 @@ create or replace function net.http_get( -- key/value pairs to be url encoded and appended to the `url` params jsonb default '{}'::jsonb, -- key/values to be included in request headers - headers jsonb default '{}'::jsonb + headers jsonb default '{}'::jsonb, + -- the maximum number of milliseconds the request may take before being cancelled + timeout_milliseconds int default 1000 ) -- request_id reference returns bigint @@ -109,11 +113,12 @@ begin from jsonb_each_text(params); -- Add to the request queue - insert into net.http_request_queue(method, url, headers) + insert into net.http_request_queue(method, url, headers, timeout_milliseconds) values ( 'GET', net._encode_url_with_params_array(url, params_array), - headers + headers, + timeout_milliseconds ) returning id into request_id; @@ -132,7 +137,9 @@ create or replace function net.http_post( -- key/value pairs to be url encoded and appended to the `url` params jsonb default '{}'::jsonb, -- key/values to be included in request headers - headers jsonb default '{"Content-Type": "application/json"}'::jsonb + headers jsonb default '{"Content-Type": "application/json"}'::jsonb, + -- the maximum number of milliseconds the request may take before being cancelled + timeout_milliseconds int DEFAULT 1000 ) -- request_id reference returns bigint @@ -180,12 +187,13 @@ begin jsonb_each_text(params); -- Add to the request queue - insert into net.http_request_queue(method, url, headers, body) + insert into net.http_request_queue(method, url, headers, body, timeout_milliseconds) values ( 'POST', net._encode_url_with_params_array(url, params_array), headers, - body::text::bytea + body::text::bytea, + timeout_milliseconds ) returning id into request_id;