Skip to content

Commit 8c48635

Browse files
authored
Merge pull request #9 from ZorTik/dev
Dev
2 parents 251743e + de0a090 commit 8c48635

File tree

24 files changed

+435
-103
lines changed

24 files changed

+435
-103
lines changed

.github/workflows/jest.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ jobs:
3737
- name: Prisma migrate
3838
run: npx prisma migrate deploy
3939
- name: Run tests
40-
run: npm test
40+
run: npm test
41+
- name: Publish Test Summary Results
42+
run: npx github-actions-ctrf ctrf/ctrf-report.json
43+
if: always()

TODO.txt

-3
This file was deleted.

app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default async function (router: Application, options?: AppBootOptions): P
119119
appConfig,
120120
logger,
121121
debug: process.env.DEBUG === 'true',
122-
workers: !options.disableWorkers && !isInsideContainer()
122+
workers: !options?.disableWorkers && !isInsideContainer()
123123
};
124124

125125
// Service (virtualization) layer

database/models.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,30 @@ export type Database = {
1515
count(nodeId: string): Promise<number>;
1616
setServiceMeta(serviceId: string, key: string, value: any): Promise<boolean>;
1717
getServiceMeta(serviceId: string, key: string): Promise<any>;
18-
}
18+
};
1919

2020
export type SessionModel = {
2121
serviceId: string,
2222
nodeId: string,
2323
containerId: string,
24-
}
24+
};
2525

2626
export type PermaModel = {
2727
serviceId: string,
2828
template: string,
2929
nodeId: string,
3030
port: number,
3131
options: {
32-
[key: string]: any
32+
[key: string]: any,
3333
},
34+
meta?: {
35+
stopCmd?: string,
36+
}
3437
env: {
35-
[key: string]: string
38+
[key: string]: string,
3639
},
3740
network?: {
3841
address: string,
3942
portsOnly: boolean,
4043
}
41-
}
44+
};

engine/asyncp.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
export type UnlockObserver = (id: string, status?: string) => void;
1+
export type UnlockObserver = (id: string, status?: string, err?: any) => void;
22

33
const statuses = {};
44
const status_types = {};
55
const obs: Map<string, UnlockObserver[]> = new Map();
6+
const obsAll: (() => void)[] = [];
67

78
let stopping = false;
89

@@ -17,11 +18,17 @@ export function lockBusyAction(id: string, tp: string) {
1718
reqNotPending(id);
1819
statuses[id] = true;
1920
status_types[id] = tp; // type of action
20-
return () => {
21+
return (err?: any) => {
2122
delete statuses[id];
2223
delete status_types[id];
2324
//
24-
(obs.get(id) ?? []).forEach(o => o(id, tp));
25+
(obs.get(id) ?? []).forEach(o => o(id, tp, err));
26+
obs.delete(id);
27+
//
28+
if (pendingCount() == 0) {
29+
obsAll.forEach(o => o());
30+
obsAll.splice(0, obsAll.length);
31+
}
2532
}
2633
}
2734

@@ -30,7 +37,15 @@ export function whenUnlocked(id: string, cb: UnlockObserver) {
3037
obs.set(id, obs.get(id) ?? []);
3138
obs.get(id).push(cb);
3239
} else {
33-
cb(id, undefined);
40+
cb(id, undefined, undefined);
41+
}
42+
}
43+
44+
export function whenUnlockedAll(cb: () => void) {
45+
if (pendingCount() > 0) {
46+
obsAll.push(cb);
47+
} else {
48+
cb();
3449
}
3550
}
3651

@@ -58,4 +73,10 @@ export function reqNotPending(id: string) {
5873

5974
export function setStopping() {
6075
stopping = true;
76+
}
77+
78+
export function pendingCount() {
79+
return Object.keys(statuses)
80+
.filter(k => statuses[k])
81+
.length;
6182
}

engine/docker/action/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export default function (self: ServiceEngine, client: DockerClient): ServiceEngi
226226
srvLog.info('Watching changes');
227227
// Watcher
228228
setTimeout(async () => {
229-
const attachOptions = { stream: true, stdout: true, hijack: true };
229+
const attachOptions = { stream: true, stdin: true, stdout: true, stderr: true, hijack: true };
230230
const rws = await client.getContainer(container.id).attach(attachOptions);
231231
rws.on('data', (data) => {
232232
logService(volumeId, data);

engine/docker/action/build.worker.ts

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const tag = workerData['imageTag'] as string;
88
const env = workerData['env'] as any;
99
const debug = workerData['debug'] as boolean;
1010

11-
if (debug) {
12-
console.log("Initializing docker client inside worker.");
13-
}
14-
1511
const client = initDockerClient(appConfig);
1612
const logs = [];
1713

engine/docker/action/cmd.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function (self: ServiceEngine, _: DockerClient): ServiceEngine['c
66
const watchers = (self as DockerServiceEngine).rws;
77
//
88
if (id in watchers) {
9-
watchers[id].write(cmd);
9+
watchers[id].write(cmd + '\n');
1010
return true;
1111
} else {
1212
return false;

0 commit comments

Comments
 (0)