UNPKG

blazerjob

Version:

TypeScript library for scheduling, executing, and managing asynchronous tasks (custom, HTTP) with a SQLite backend.

29 lines (28 loc) 1.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeHttpTaskFn = makeHttpTaskFn; const node_fetch_1 = __importDefault(require("node-fetch")); /** * Fabrique une fonction de tâche HTTP pour BlazeJob */ function makeHttpTaskFn(cfg) { return async () => { console.log('[DEBUG][HTTP] URL utilisée pour fetch:', cfg.url); const res = await (0, node_fetch_1.default)(cfg.url, { method: cfg.method ?? 'POST', headers: cfg.headers, body: cfg.body ? JSON.stringify(cfg.body) : undefined }); if (!res.ok) { const text = await res.text(); // Log la réponse pour debug console.log('[HTTP][response]', text); throw new Error(`[HTTP] Code de retour ${res.status} pour ${cfg.url}`); } const text = await res.text(); console.log('[HTTP][response]', text); }; }