Fix issue where all jobs were loaded as multiSend
This commit is contained in:
@@ -47,8 +47,12 @@ export class Job {
|
|||||||
|
|
||||||
static deserialize(serialized: any): Job {
|
static deserialize(serialized: any): Job {
|
||||||
if (!serialized.pdu || !serialized.pdu.command) {
|
if (!serialized.pdu || !serialized.pdu.command) {
|
||||||
|
if (!serialized.perSecond && !serialized.count) {
|
||||||
|
return Job.createEmptySingle();
|
||||||
|
} else {
|
||||||
return Job.createEmptyMultiple();
|
return Job.createEmptyMultiple();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let pdu: any = new smpp.PDU(serialized.pdu.command, serialized.pdu);
|
let pdu: any = new smpp.PDU(serialized.pdu.command, serialized.pdu);
|
||||||
return new Job(pdu, serialized.perSecond, serialized.count);
|
return new Job(pdu, serialized.perSecond, serialized.count);
|
||||||
}
|
}
|
||||||
@@ -61,7 +65,7 @@ export class Job {
|
|||||||
return new Job({}, 1, 1);
|
return new Job({}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(req: any) {
|
update(req: any): void {
|
||||||
if (req.body.source != this._pdu.source_addr) {
|
if (req.body.source != this._pdu.source_addr) {
|
||||||
this._pdu.source_addr = req.body.source;
|
this._pdu.source_addr = req.body.source;
|
||||||
}
|
}
|
||||||
@@ -71,10 +75,10 @@ export class Job {
|
|||||||
if (req.body.message != this._pdu.short_message) {
|
if (req.body.message != this._pdu.short_message) {
|
||||||
this._pdu.short_message = req.body.message;
|
this._pdu.short_message = req.body.message;
|
||||||
}
|
}
|
||||||
if (!!req.body.perSecond && req.body.perSecond != this._perSecond) {
|
if (!!this._perSecond && !!req.body.perSecond && req.body.perSecond != this._perSecond) {
|
||||||
this._perSecond = req.body.perSecond;
|
this._perSecond = req.body.perSecond;
|
||||||
}
|
}
|
||||||
if (!!req.body.count && req.body.count != this._count) {
|
if (!!this._count && !!req.body.count && req.body.count != this._count) {
|
||||||
this._count = req.body.count;
|
this._count = req.body.count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,24 @@ export abstract class SessionManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup(): void {
|
||||||
|
try {
|
||||||
|
this.logger.log1(`Loading ${this.ManagedSessionClass.name} from ${this.StorageFile}`)
|
||||||
|
let sessions: Buffer = fs.readFileSync(this.StorageFile);
|
||||||
|
let loadedSessions: any[] = JSON.parse(String(sessions));
|
||||||
|
this.logger.log1(`Loaded ${loadedSessions.length} clients from ${this.StorageFile}`);
|
||||||
|
loadedSessions.forEach(session => {
|
||||||
|
this.createSession(session.url || session.port, session.username, session.password).then((sessionObj: SmppSession) => {
|
||||||
|
sessionObj.setDefaultSingleJob(Job.deserialize(session.defaultSingleJob));
|
||||||
|
sessionObj.setDefaultMultipleJob(Job.deserialize(session.defaultMultipleJob));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.log1(`Error loading centers from ${this.StorageFile}: ${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createSession(arg: any, username: string, password: string): Promise<SmppSession> {
|
createSession(arg: any, username: string, password: string): Promise<SmppSession> {
|
||||||
return new Promise<SmppSession>((resolve, reject) => {
|
return new Promise<SmppSession>((resolve, reject) => {
|
||||||
this.logger.log1(`Creating session of type ${this.ManagedSessionClass.name} with arg ${arg}`);
|
this.logger.log1(`Creating session of type ${this.ManagedSessionClass.name} with arg ${arg}`);
|
||||||
@@ -77,30 +95,12 @@ export abstract class SessionManager {
|
|||||||
|
|
||||||
verifyField(field: string, reject: (reason?: any) => void) {
|
verifyField(field: string, reject: (reason?: any) => void) {
|
||||||
if (!field) {
|
if (!field) {
|
||||||
let error = `Request to make a new client failed because of missing ${field}.`;
|
let error = `Request to make a new session failed because of missing ${field}.`;
|
||||||
this.logger.log1(error);
|
this.logger.log1(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setup(): void {
|
|
||||||
try {
|
|
||||||
this.logger.log1(`Loading ${this.ManagedSessionClass.name} from ${this.StorageFile}`)
|
|
||||||
let sessions: Buffer = fs.readFileSync(this.StorageFile);
|
|
||||||
let loadedSessions: any[] = JSON.parse(String(sessions));
|
|
||||||
this.logger.log1(`Loaded ${loadedSessions.length} clients from ${this.StorageFile}`);
|
|
||||||
loadedSessions.forEach(session => {
|
|
||||||
this.createSession(session.url, session.username, session.password).then((sessionObj: SmppSession) => {
|
|
||||||
sessionObj.setDefaultSingleJob(Job.deserialize(session.defaultSingleJob));
|
|
||||||
sessionObj.setDefaultMultipleJob(Job.deserialize(session.defaultMultipleJob));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
this.logger.log1(`Error loading centers from ${this.StorageFile}: ${e}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup(): void {
|
cleanup(): void {
|
||||||
this.logger.log1(`Saving centers to ${this.StorageFile}...`);
|
this.logger.log1(`Saving centers to ${this.StorageFile}...`);
|
||||||
fs.writeFileSync(this.StorageFile, JSON.stringify(this.serialize(), null, 4));
|
fs.writeFileSync(this.StorageFile, JSON.stringify(this.serialize(), null, 4));
|
||||||
|
@@ -29,7 +29,7 @@ function cleanup(): void {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', cleanup);
|
// process.on('exit', cleanup);
|
||||||
process.on('SIGINT', cleanup);
|
// process.on('SIGINT', cleanup);
|
||||||
process.on('SIGUSR1', cleanup);
|
// process.on('SIGUSR1', cleanup);
|
||||||
process.on('SIGUSR2', cleanup);
|
// process.on('SIGUSR2', cleanup);
|
Reference in New Issue
Block a user