@acurast/cli
Version:
A cli to interact with the Acurast Cloud.
40 lines • 2.42 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { AcurastService } from '../acurast/env/acurastService.js';
import { JobEnvironmentService } from '../acurast/env/jobEnvironmentService.js';
import { getWallet } from './getWallet.js';
import { toNumber } from './jobToNumber.js';
export const setEnvVars = (job, wallet) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const acurast = new AcurastService();
// If a wallet is not provided, get the one from the environment configuration
wallet || (wallet = yield getWallet());
const assignedProcessors = yield acurast.assignedProcessors([
[{ acurast: job.id[0].acurast }, Number(toNumber(job.id[1]))],
]);
const keys = Array.from(assignedProcessors.entries()).flatMap(([_, [jobId, processors]]) => processors.map((account) => [account, jobId]));
const jobAssignmentInfos = yield acurast.jobAssignments(keys);
const envVars = (_a = job.envVars) !== null && _a !== void 0 ? _a : [];
if (envVars.length === 0) {
console.log('No environment variables found for deployment', job.id[1]);
return {};
}
if (jobAssignmentInfos.length === 0 ||
jobAssignmentInfos.every((info) => info.assignment.pubKeys.length === 0)) {
// If no pubkeys are present, it means that the match is done, but has not been acknowledged.
// We wait a little and try again.
yield new Promise((resolve) => setTimeout(resolve, 30000));
return setEnvVars(job);
}
const jobEnvironmentService = new JobEnvironmentService();
const res = yield jobEnvironmentService.setEnvironmentVariablesMulti(wallet, jobAssignmentInfos, Number(toNumber(job.id[1])), envVars);
return { hash: res.hash };
});
//# sourceMappingURL=setEnvVars.js.map