UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

51 lines 2.25 kB
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 './acurastService.js'; import { sameJobIds } from './utils.js'; // TODO: Remove this file? It's not used anymore export class JobEnvHelper { constructor() { this.assignments = []; } setEnvVars(job, envVars) { return __awaiter(this, void 0, void 0, function* () { console.log('Setting env variables', job, envVars); this.watchJobAssignments(job); }); } watchJobAssignments(job) { return __awaiter(this, void 0, void 0, function* () { this.unsubJobAssignment(); const acurast = new AcurastService(); this.jobAssignmentUnsub = yield acurast.subscribeToJobAssignmentEvents((assignment) => { if (!sameJobIds(assignment.id, job.id)) { return; } const index = this.assignments.findIndex((value) => assignment.processor === value.processor); if (index < 0) { this.assignments = [...this.assignments, assignment]; } else { const current = this.assignments; current[index] = assignment; this.assignments = current; } console.log('assignments', this.assignments); }); }); } unsubJobAssignment() { if (this.jobAssignmentUnsub) { this.jobAssignmentUnsub(); this.jobAssignmentUnsub = undefined; } } } //# sourceMappingURL=environmentVars.js.map