MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / watchDomainTask

Function watchDomainTask

static/js/accounts.js:76–113  ·  view source on GitHub ↗
(fetchTask, onUpdate, maxWaitMs = 20 * 60 * 1000, options = {})

Source from the content-addressed store, hash-verified

74}
75
76async function watchDomainTask(fetchTask, onUpdate, maxWaitMs = 20 * 60 * 1000, options = {}) {
77 const startedAt = Date.now();
78 const poller = createAdaptivePoller({
79 baseIntervalMs: Number(options.baseIntervalMs || 1200),
80 maxIntervalMs: Number(options.maxIntervalMs || 12000),
81 });
82 let lastError = null;
83
84 while (Date.now() - startedAt < maxWaitMs) {
85 try {
86 const task = await fetchTask();
87 poller.recordSuccess();
88
89 if (typeof onUpdate === 'function') {
90 onUpdate(task);
91 }
92
93 const status = String(task?.status || '').toLowerCase();
94 if (TASK_TERMINAL_STATUSES.has(status)) {
95 return task;
96 }
97 } catch (error) {
98 lastError = error;
99 const statusCode = Number(error?.response?.status || 0);
100 if (statusCode === 404) {
101 throw error;
102 }
103 poller.recordError();
104 }
105
106 await sleep(poller.nextDelay({ forceSlow: !api.networkOnline }));
107 }
108
109 if (lastError && lastError.message) {
110 throw new Error(`任务等待超时: ${lastError.message}`);
111 }
112 throw new Error('任务等待超时,请稍后刷新查看结果');
113}
114
115async function watchAccountTask(taskId, onUpdate, maxWaitMs = 20 * 60 * 1000) {
116 return watchDomainTask(

Callers 2

watchAccountTaskFunction · 0.85
watchPaymentTaskFunction · 0.85

Calls 5

createAdaptivePollerFunction · 0.85
recordSuccessMethod · 0.80
recordErrorMethod · 0.80
nextDelayMethod · 0.80
sleepFunction · 0.70

Tested by

no test coverage detected