fix(core): update
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartdata',
|
||||
version: '5.0.24',
|
||||
version: '5.0.25',
|
||||
description: 'do more with data'
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { Manager, setDefaultManagerForDoc } from './smartdata.classes.collection
|
||||
import { SmartDataDbDoc, svDb, unI } from './smartdata.classes.doc.js';
|
||||
|
||||
@Manager()
|
||||
class DistributedClass extends SmartDataDbDoc<DistributedClass, DistributedClass> {
|
||||
export class DistributedClass extends SmartDataDbDoc<DistributedClass, DistributedClass> {
|
||||
// INSTANCE
|
||||
@unI()
|
||||
public id: string;
|
||||
@ -37,14 +37,13 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
public readyPromise: Promise<any>;
|
||||
public db: SmartdataDb;
|
||||
private asyncExecutionStack = new plugins.lik.AsyncExecutionStack();
|
||||
private ownInstance: DistributedClass;
|
||||
public ownInstance: DistributedClass;
|
||||
|
||||
constructor(dbArg?: SmartdataDb) {
|
||||
constructor(dbArg: SmartdataDb) {
|
||||
super();
|
||||
this.db = dbArg;
|
||||
setDefaultManagerForDoc(this, DistributedClass);
|
||||
this.readyPromise = this.db.statusConnectedDeferred.promise;
|
||||
this.init();
|
||||
}
|
||||
|
||||
// smartdata specific stuff
|
||||
@ -64,15 +63,19 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
|
||||
private startHeartbeat = async () => {
|
||||
while (this.ownInstance.data.status !== 'stopped') {
|
||||
await this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||
await this.ownInstance.updateFromDb();
|
||||
this.ownInstance.data.lastUpdated = Date.now();
|
||||
await this.ownInstance.save();
|
||||
});
|
||||
await this.sendHeartbeat();
|
||||
await plugins.smartdelay.delayFor(10000);
|
||||
}
|
||||
};
|
||||
public async init() {
|
||||
|
||||
public async sendHeartbeat() {
|
||||
await this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||
await this.ownInstance.updateFromDb();
|
||||
this.ownInstance.data.lastUpdated = Date.now();
|
||||
await this.ownInstance.save();
|
||||
});
|
||||
}
|
||||
private async init() {
|
||||
await this.readyPromise;
|
||||
if (!this.ownInstance) {
|
||||
await this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
|
||||
@ -86,7 +89,9 @@ export class SmartdataDistributedCoordinator extends plugins.taskbuffer.distribu
|
||||
taskRequestResults: [],
|
||||
};
|
||||
await this.ownInstance.save();
|
||||
console.log('saved own instance.')
|
||||
});
|
||||
console.log('yep, we are here')
|
||||
}
|
||||
|
||||
// lets enable the heartbeat
|
||||
|
Reference in New Issue
Block a user