@defer.run/client
Advanced tools
Comparing version 0.1.0-alpha-20221220162232-f42c41b to 0.1.0-alpha-20221220162633-53d11d7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.INTERNAL_VERSION = exports.FN_EXECUTION_POLLING_INTERVAL = exports.TOKEN_ENV_NAME = exports.PATH = exports.DOMAIN = void 0; | ||
exports.FN_EXECUTION_POLLING_INTERVAL_SECS = exports.TOKEN_ENV_NAME = exports.PATH = exports.DOMAIN = void 0; | ||
exports.DOMAIN = "https://api.defer.run"; | ||
exports.PATH = "/api/v1/"; | ||
exports.TOKEN_ENV_NAME = "DEFER_TOKEN"; | ||
exports.FN_EXECUTION_POLLING_INTERVAL = 1000; | ||
exports.INTERNAL_VERSION = 2; | ||
exports.FN_EXECUTION_POLLING_INTERVAL_SECS = 2; |
@@ -56,4 +56,10 @@ "use strict"; | ||
exports.serializeBackgroundFunctionArguments = serializeBackgroundFunctionArguments; | ||
const jitter = (attempt) => Math.floor(Math.random() * | ||
(Math.min(15, Math.pow(constants_js_1.FN_EXECUTION_POLLING_INTERVAL_SECS * 2, attempt)) - | ||
0 + | ||
1) + | ||
0); | ||
// TODO(charly): handler error cases | ||
function poolForExecutionResult(fnName, runId, fetcher, debug = false) { | ||
let attempt = 1; | ||
const getResult = async () => fetcher(`executions/${runId}`, { | ||
@@ -78,7 +84,8 @@ method: "GET", | ||
} | ||
setTimeout(poll, constants_js_1.FN_EXECUTION_POLLING_INTERVAL); | ||
setTimeout(poll, jitter(attempt++) * 1000); | ||
}; | ||
poll(); | ||
// initial call | ||
setTimeout(poll, jitter(attempt++) * 1000); | ||
}); | ||
} | ||
exports.poolForExecutionResult = poolForExecutionResult; |
@@ -40,3 +40,2 @@ "use strict"; | ||
ret.__fn = fn; | ||
ret.__version = constants_js_1.INTERNAL_VERSION; | ||
return ret; | ||
@@ -56,4 +55,3 @@ }; | ||
ret.__fn = fn; | ||
ret.__version = constants_js_1.INTERNAL_VERSION; | ||
return ret; | ||
}; |
export const DOMAIN = "https://api.defer.run"; | ||
export const PATH = "/api/v1/"; | ||
export const TOKEN_ENV_NAME = "DEFER_TOKEN"; | ||
export const FN_EXECUTION_POLLING_INTERVAL = 1000; | ||
export const INTERNAL_VERSION = 2; | ||
export const FN_EXECUTION_POLLING_INTERVAL_SECS = 2; |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { FN_EXECUTION_POLLING_INTERVAL } from "./constants.js"; | ||
import { FN_EXECUTION_POLLING_INTERVAL_SECS } from "./constants.js"; | ||
export function executeBackgroundFunction(fnName, args, fetcher, debug = false) { | ||
@@ -51,4 +51,10 @@ return new Promise((resolve, reject) => { | ||
} | ||
const jitter = (attempt) => Math.floor(Math.random() * | ||
(Math.min(15, Math.pow(FN_EXECUTION_POLLING_INTERVAL_SECS * 2, attempt)) - | ||
0 + | ||
1) + | ||
0); | ||
// TODO(charly): handler error cases | ||
export function poolForExecutionResult(fnName, runId, fetcher, debug = false) { | ||
let attempt = 1; | ||
const getResult = async () => fetcher(`executions/${runId}`, { | ||
@@ -73,6 +79,7 @@ method: "GET", | ||
} | ||
setTimeout(poll, FN_EXECUTION_POLLING_INTERVAL); | ||
setTimeout(poll, jitter(attempt++) * 1000); | ||
}; | ||
poll(); | ||
// initial call | ||
setTimeout(poll, jitter(attempt++) * 1000); | ||
}); | ||
} |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { DOMAIN, INTERNAL_VERSION, PATH, TOKEN_ENV_NAME } from "./constants.js"; | ||
import { DOMAIN, PATH, TOKEN_ENV_NAME } from "./constants.js"; | ||
import { executeBackgroundFunction, poolForExecutionResult, serializeBackgroundFunctionArguments, } from "./execute.js"; | ||
@@ -35,3 +35,2 @@ import { makeFetcher } from "./fetcher.js"; | ||
ret.__fn = fn; | ||
ret.__version = INTERNAL_VERSION; | ||
return ret; | ||
@@ -50,4 +49,3 @@ }; | ||
ret.__fn = fn; | ||
ret.__version = INTERNAL_VERSION; | ||
return ret; | ||
}; |
{ | ||
"name": "@defer.run/client", | ||
"version": "0.1.0-alpha-20221220162232-f42c41b", | ||
"version": "0.1.0-alpha-20221220162633-53d11d7", | ||
"description": "cua JavaScript client", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
export declare const DOMAIN = "https://api.defer.run"; | ||
export declare const PATH = "/api/v1/"; | ||
export declare const TOKEN_ENV_NAME = "DEFER_TOKEN"; | ||
export declare const FN_EXECUTION_POLLING_INTERVAL = 1000; | ||
export declare const INTERNAL_VERSION = 2; | ||
export declare const FN_EXECUTION_POLLING_INTERVAL_SECS = 2; |
@@ -13,3 +13,2 @@ import { DeferExecuteResponse } from "./execute.js"; | ||
__fn: F; | ||
__version: number; | ||
} | ||
@@ -19,3 +18,2 @@ interface DeferAwaitRetFn<F extends (...args: any | undefined) => Promise<any>> { | ||
__fn: F; | ||
__version: number; | ||
} | ||
@@ -22,0 +20,0 @@ interface Defer { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19536
359