MVP back end
This commit is contained in:
parent
528b9f67d4
commit
889fc95c3d
51 changed files with 1048 additions and 426 deletions
|
@ -1,10 +1,10 @@
|
|||
import cluster, { Worker } from "node:cluster";
|
||||
import { TypedEvent } from "../helper/typed_event.js";
|
||||
import { Result } from "../helper/result.js";
|
||||
import { WorkerDataExec, WorkerType } from "../helper/worker_computed.js";
|
||||
import { delay } from "../helper/delay.js";
|
||||
import { ExecutorResult } from "../model/executor_result.js";
|
||||
import { EXEC_TYPE, ExecError, SpawnError } from "../model/exec_error_model.js";
|
||||
import { TypedEvent } from "../helper/typed_event";
|
||||
import { Result } from "../helper/result";
|
||||
import { WorkerDataExec, WorkerType } from "../helper/worker_computed";
|
||||
import { delay } from "../helper/delay";
|
||||
import { ExecutorResult } from "../model/executor_result";
|
||||
import { EXEC_TYPE, ExecError, SpawnError } from "../model/exec_error_model";
|
||||
|
||||
abstract class IExecutorProgramService {
|
||||
abstract execPath: string;
|
||||
|
@ -31,7 +31,7 @@ export class ExecutorProgramService
|
|||
args: Array<string> | undefined = undefined
|
||||
) {
|
||||
cluster.setupPrimary({
|
||||
exec: "./src/core/helper/worker_computed.js",
|
||||
exec: "./src/core/helper/worker_computed",
|
||||
});
|
||||
|
||||
const worker = cluster.fork();
|
||||
|
|
|
@ -7,16 +7,16 @@ import { BinaryLike } from "crypto";
|
|||
import {
|
||||
EventsFileChanger,
|
||||
MetaDataFileManagerModel,
|
||||
} from "../model/meta_data_file_manager_model.js";
|
||||
import { Result } from "../helper/result.js";
|
||||
import { TypedEvent } from "../helper/typed_event.js";
|
||||
} from "../model/meta_data_file_manager_model";
|
||||
import { Result } from "../helper/result";
|
||||
import { TypedEvent } from "../helper/typed_event";
|
||||
|
||||
const readFileAsync = promisify(fs.readFile);
|
||||
const readdir = promisify(fs.readdir);
|
||||
const stat = promisify(fs.stat);
|
||||
const lsStat = promisify(fs.lstat);
|
||||
|
||||
function joinBuffers(buffers, delimiter = " ") {
|
||||
function joinBuffers(buffers: Array<Buffer>, delimiter = " ") {
|
||||
const d = Buffer.from(delimiter);
|
||||
return buffers.reduce((prev, b) => Buffer.concat([prev, d, b]));
|
||||
}
|
||||
|
@ -44,8 +44,6 @@ export interface IHashesCache {
|
|||
[key: string]: MetaDataFileManagerModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export abstract class IFilesChangeNotifierService {
|
||||
abstract directory: string;
|
||||
}
|
||||
|
|
|
@ -1,43 +1,40 @@
|
|||
import {
|
||||
FilesChangeNotifierService,
|
||||
IHashesCache,
|
||||
} from "./files_change_notifier_service.js";
|
||||
import { ProcessMetaData, Trigger } from "../model/process_model.js";
|
||||
import { ExecutorProgramService } from "./executor_program_service.js";
|
||||
import {
|
||||
EXEC_EVENT,
|
||||
ExecError,
|
||||
SpawnError,
|
||||
} from "../model/exec_error_model.js";
|
||||
import { TypedEvent } from "../helper/typed_event.js";
|
||||
import { Result } from "../helper/result.js";
|
||||
import { ExecutorResult } from "../model/executor_result.js";
|
||||
import { delay } from "../helper/delay.js";
|
||||
import { TriggerErrorReport, TriggerService } from "./trigger_service.js";
|
||||
} from "./files_change_notifier_service";
|
||||
import { IPipeline } from "../model/process_model";
|
||||
import { ExecutorProgramService } from "./executor_program_service";
|
||||
import { EXEC_EVENT, ExecError, SpawnError } from "../model/exec_error_model";
|
||||
import { TypedEvent } from "../helper/typed_event";
|
||||
import { Result } from "../helper/result";
|
||||
import { ExecutorResult } from "../model/executor_result";
|
||||
import { delay } from "../helper/delay";
|
||||
import { TriggerService } from "./trigger_service";
|
||||
import { Trigger } from "../../features/triggers/trigger_model";
|
||||
|
||||
export interface Iteration {
|
||||
hashes: IHashesCache | null;
|
||||
process: ProcessMetaData;
|
||||
process: IPipeline;
|
||||
result?: ExecError | SpawnError | ExecutorResult;
|
||||
}
|
||||
|
||||
export abstract class IStackService {
|
||||
abstract callStack: Iteration[];
|
||||
abstract path: string;
|
||||
abstract init(processed: ProcessMetaData[], path: string): void;
|
||||
abstract init(processed: IPipeline[], path: string): void;
|
||||
}
|
||||
|
||||
export class StackService extends TypedEvent<string> implements IStackService {
|
||||
callStack: Iteration[];
|
||||
path: string;
|
||||
constructor(processed: ProcessMetaData[], path: string) {
|
||||
constructor(processed: IPipeline[], path: string) {
|
||||
super();
|
||||
this.path = path;
|
||||
this.callStack = [];
|
||||
this.init(processed);
|
||||
}
|
||||
|
||||
public init(processed: ProcessMetaData[]) {
|
||||
public init(processed: IPipeline[]) {
|
||||
for (let el of processed) {
|
||||
el = this.commandHandler(el);
|
||||
this.callStack.push({
|
||||
|
@ -46,7 +43,7 @@ export class StackService extends TypedEvent<string> implements IStackService {
|
|||
});
|
||||
}
|
||||
}
|
||||
private commandHandler(processMetaData: ProcessMetaData) {
|
||||
private commandHandler(processMetaData: IPipeline) {
|
||||
processMetaData.process.command = processMetaData.process.command.replace(
|
||||
"$PATH",
|
||||
this.path
|
||||
|
@ -91,10 +88,10 @@ export class StackService extends TypedEvent<string> implements IStackService {
|
|||
);
|
||||
triggerResult.fold(
|
||||
(s) => {
|
||||
s
|
||||
s;
|
||||
},
|
||||
(e) => {
|
||||
e;
|
||||
e;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Trigger, TriggerType } from "../model/process_model.js";
|
||||
import * as vm from "node:vm";
|
||||
import { IHashesCache } from "./files_change_notifier_service.js";
|
||||
import { EventsFileChanger } from "../model/meta_data_file_manager_model.js";
|
||||
import { Result } from "../helper/result.js";
|
||||
import { TypedEvent } from "../helper/typed_event.js";
|
||||
import { IHashesCache } from "./files_change_notifier_service";
|
||||
import { EventsFileChanger } from "../model/meta_data_file_manager_model";
|
||||
import { Result } from "../helper/result";
|
||||
import { TypedEvent } from "../helper/typed_event";
|
||||
import { Trigger, TriggerType } from "../../features/triggers/trigger_model";
|
||||
|
||||
export class TriggerCallResult {
|
||||
results: Array<TriggerSuccessResult | TriggerErrorReport>;
|
||||
|
@ -47,7 +47,7 @@ export class TriggerErrorReport extends Error {
|
|||
}
|
||||
}
|
||||
export class TriggerService extends TypedEvent<TriggerCallResult> {
|
||||
context = {};
|
||||
context: any = {};
|
||||
|
||||
constructor(trigger: Trigger, hashes: IHashesCache, path: string) {
|
||||
super();
|
||||
|
@ -61,8 +61,11 @@ export class TriggerService extends TypedEvent<TriggerCallResult> {
|
|||
path: string;
|
||||
hashes: IHashesCache;
|
||||
trigger: Trigger;
|
||||
|
||||
private init(): void {
|
||||
this.context["hashes"] = this.hashes;
|
||||
if (this.context["hashes"] != undefined) {
|
||||
this.context["hashes"] = this.hashes;
|
||||
}
|
||||
}
|
||||
private getAllHashesDeleteWithouts(): string[] {
|
||||
return Object.entries(this.hashes).map(([k, v]) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue