Skip to content

Commit c7ae3a0

Browse files
fix: set env loop
1 parent 2df6e24 commit c7ae3a0

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/commands/deployments.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,55 @@ export const addCommandDeployments = (program: Command) => {
243243
throw new Error('No environment variables found for deployment')
244244
}
245245

246+
// TODO: drop this precheck once @acurast/sdk setEnvVars exposes
247+
// maxRetries / abortIfPastStartMs options. Today the SDK recurses
248+
// every 30s with no bail, so we gate the call here instead.
249+
const MAX_ATTEMPTS = 20
250+
const RETRY_MS = 30_000
251+
const startTime =
252+
deploymentFileData.registration?.schedule?.startTime
253+
const abortAtMs =
254+
startTime && startTime > Date.now()
255+
? startTime - 60_000
256+
: undefined
257+
258+
const precheckService = new AcurastService(rpcEndpoint)
259+
await precheckService.connect()
260+
if (!precheckService.api) {
261+
throw new Error('API not connected')
262+
}
263+
264+
let ready = false
265+
let lastError: string | undefined
266+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
267+
if (abortAtMs !== undefined && Date.now() >= abortAtMs) {
268+
lastError = `deployment start time is within 60s (or has passed) — env vars cannot reach processors in time.`
269+
break
270+
}
271+
const assignments = await getAcknowledgedProcessors(
272+
precheckService.api,
273+
job.id
274+
)
275+
if (
276+
assignments.some((a) => a.assignment.pubKeys.length > 0)
277+
) {
278+
ready = true
279+
break
280+
}
281+
spinner.text = `Waiting for processor encryption keys (attempt ${attempt}/${MAX_ATTEMPTS})...`
282+
if (attempt < MAX_ATTEMPTS) {
283+
await new Promise((r) => setTimeout(r, RETRY_MS))
284+
} else {
285+
lastError = `no assigned processor has published encryption keys after ${MAX_ATTEMPTS} attempts.`
286+
}
287+
}
288+
await precheckService.disconnect()
289+
290+
if (!ready) {
291+
spinner.fail(`Env vars not set: ${lastError}`)
292+
throw new Error(`setEnvVars aborted: ${lastError}`)
293+
}
294+
246295
const { hash } = await setEnvVars(job, {
247296
wallet,
248297
rpcEndpoint,

0 commit comments

Comments
 (0)