backend-plus 2.0.0-rc.10 → 2.0.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -420,7 +420,8 @@ export class AppBackend{
420
420
  i18n:{
421
421
  messages:Record<LangId,Record<string, string>>
422
422
  }
423
- shootDownBackend():Promise<void>
423
+ shutdownCallbackListAdd(param:{message:string, fun:()=>Promise<void>}):void
424
+ shutdownBackend():Promise<void>
424
425
  setLog(opts:{until:string, results?:boolean}):void
425
426
  getDataDumpTransformations(rawData:string):Promise<{rawData:string, prepareTransformationSql:string[], endTransformationSql:string[]}>
426
427
  }
@@ -97,7 +97,13 @@ class AppBackend{
97
97
  /** @type {{path:string}[]} */
98
98
  this.appStack=[];
99
99
  /** @type {{message:string; fun:()=>void}[]} */
100
- this.shootDownCallbackList=[];
100
+ this.shutdownCallbackList=[];
101
+ this.sessionStores={
102
+ file: SessionFileStore,
103
+ memory: memorystore,
104
+ memoryDevel: BindMemoryPerodicallySaved(this),
105
+ "memory-saved": BindMemoryPerodicallySaved(this),
106
+ }
101
107
  if(!this.rootPath){
102
108
  console.log('ATENCIÓN hay que poner be.rootPath antes de llamar a super()');
103
109
  this.rootPath=Path.resolve(__dirname,'..');
@@ -119,7 +125,7 @@ class AppBackend{
119
125
  this.tableStructures = {};
120
126
  this.configStaticConfig();
121
127
  /** @type {null|()=>Promise<void>} */
122
- this.shootDownBackend = null;
128
+ this.shutdownBackend = null;
123
129
  /** @type {bp.Server} */
124
130
  // @ts-ignore
125
131
  this.server = null;
@@ -358,6 +364,8 @@ AppBackend.prototype.i18n.messages.es={
358
364
  }
359
365
  };
360
366
 
367
+ function BindMemoryPerodicallySaved(be){
368
+ return (
361
369
  /**
362
370
  * @param {Express.Session} session
363
371
  */
@@ -406,7 +414,7 @@ function MemoryPerodicallySaved(session){
406
414
  console.log('dumping sessions every',dumpEverySeconds,'seconds');
407
415
  var errorsToShow=4;
408
416
  // TODO: hangs the server in devel mode
409
- setInterval(function(){
417
+ var interval = setInterval(function(){
410
418
  try{
411
419
  fs.writeFile(fileName,json4all.stringify(store.store.dump()));
412
420
  }catch(err){
@@ -417,18 +425,15 @@ function MemoryPerodicallySaved(session){
417
425
  }
418
426
  }
419
427
  },dumpEverySeconds*1000);
428
+ be.shutdownCallbackListAdd({
429
+ message:'session saver',
430
+ fun:()=>clearInterval(interval)
431
+ })
420
432
  });
421
433
  }
422
434
  }
423
435
  return MemoryDevelConstructor;
424
- }
425
-
426
- var sessionStores={
427
- file: SessionFileStore,
428
- memory: memorystore,
429
- memoryDevel: MemoryPerodicallySaved,
430
- "memory-saved": MemoryPerodicallySaved,
431
- }
436
+ })}
432
437
 
433
438
  /**
434
439
  * @param {string} text
@@ -504,6 +509,11 @@ AppBackend.prototype.canChangePass = async function canChangePass(reqOrContext,
504
509
  return be.isAdmin(reqOrContext);
505
510
  }
506
511
 
512
+ AppBackend.prototype.shutdownCallbackListAdd = function(messageFun){
513
+ this.shutdownCallbackList.push(messageFun);
514
+ }
515
+
516
+
507
517
  AppBackend.prototype._Browsers = {
508
518
  Edge: {short:'Ed' , minVer:14 , polly:true},
509
519
  Konqueror: {short:'Kq' , minVer:null, polly:true},
@@ -626,32 +636,33 @@ AppBackend.prototype.start = function start(opts){
626
636
  // @ts-ignore : only for testing */
627
637
  this.getMainApp = function getMainApp(){ return mainApp; };
628
638
  }
629
- this.shootDownBackend = function shootDownBackend(){
639
+ this.shutdownBackend = async function shutdownBackend(){
630
640
  console.log('shooting down:');
631
- return new Promise(function(resolve,reject){
632
- console.log('*','express server');
633
- be.server.close(/** @param {Error} err */function(err){
634
- if(err){
635
- console.log('*', err)
636
- reject(err);
637
- }else{
638
- resolve();
639
- }
640
- });
641
- }).then(async function(){
642
- while(be.shootDownCallbackList.length){
643
- var nextCallback=be.shootDownCallbackList.pop();
644
- if(nextCallback!=null){
645
- console.log('*',nextCallback.message);
646
- await nextCallback.fun();
647
- }
648
- }
649
- }).then(function(){
650
- console.log('pg pool balance',pg.poolBalanceControl());
651
- // @ts-ignore al hacer shootDown ya no hay mainApp.
652
- mainApp = null;
653
- logWhy && logWhy();
654
- });
641
+ var waitFor = [
642
+ new Promise(function(resolve,reject){
643
+ console.log('*','express server');
644
+ be.server.close(/** @param {Error} err */function(err){
645
+ if(err){
646
+ console.log('*', err)
647
+ reject(err);
648
+ }else{
649
+ console.log('*','express server done!')
650
+ resolve();
651
+ }
652
+ });
653
+ }),
654
+ ...(be.shutdownCallbackList.map(x => (async function(){
655
+ console.log('shut:', x.message)
656
+ await x.fun()
657
+ console.log('done:', x.message)
658
+ })()))
659
+ ];
660
+ console.log('*', 'waiting for all')
661
+ await Promise.all(waitFor);
662
+ console.log('*', 'all done')
663
+ mainApp = null;
664
+ console.log('* logWhy',logWhy)
665
+ logWhy && logWhy();
655
666
  };
656
667
  return Promise.resolve().then(function(){
657
668
  var configList=be.configList();
@@ -682,10 +693,10 @@ AppBackend.prototype.start = function start(opts){
682
693
  }
683
694
  var sessionStoreName=be.config.server["session-store"];
684
695
  if(sessionStoreName){
685
- if(config.devel && sessionStores[sessionStoreName+'Devel']){
696
+ if(config.devel && be.sessionStores[sessionStoreName+'Devel']){
686
697
  sessionStoreName+='Devel';
687
698
  }
688
- var storeModule = sessionStores[sessionStoreName];
699
+ var storeModule = be.sessionStores[sessionStoreName];
689
700
  be.config.login.plus.store.module = storeModule;
690
701
  }
691
702
  be.config.install.dump.db.owner=coalesce(be.config.db.owner,be.config.install.dump.db.owner,be.config.db.user);
@@ -963,12 +974,18 @@ AppBackend.prototype.start = function start(opts){
963
974
  loginPlusOpts.noLoggedUrlPath=be.config.login.unloggedLandPage;
964
975
  }
965
976
  mainApp.loginPlusManager.init(mainApp,changing(be.config.login.plus,loginPlusOpts));
966
- be.shootDownCallbackList.push({
977
+ be.shutdownCallbackListAdd({
967
978
  message:'login-plus manager',
968
979
  fun:function(){
969
980
  mainApp.loginPlusManager.closeManager();
970
981
  }
971
982
  });
983
+ be.shutdownCallbackListAdd({
984
+ message:'pg',
985
+ fun:function(){
986
+ pg.shutdown();
987
+ }
988
+ });
972
989
  mainApp.loginPlusManager.setValidatorStrategy(
973
990
  function(req, username, password, done) {
974
991
  var client;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "backend-plus",
3
3
  "description": "Backend for the anti Pareto rule",
4
- "version": "2.0.0-rc.10",
4
+ "version": "2.0.0-rc.12",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/backend-plus",
@@ -82,7 +82,7 @@
82
82
  "@types/js-yaml": "^4.0.9",
83
83
  "@types/mocha": "^10.0.6",
84
84
  "@types/multiparty": "~0.0.36",
85
- "@types/node": "^20.12.2",
85
+ "@types/node": "^20.12.5",
86
86
  "@types/nodemailer": "^6.4.14",
87
87
  "@types/numeral": "~2.0.5",
88
88
  "@types/session-file-store": "^1.2.5",
@@ -99,11 +99,11 @@
99
99
  "kill-9": "~0.4.3",
100
100
  "mocha": "^10.4.0",
101
101
  "nyc": "^15.1.0",
102
- "puppeteer": "^22.6.1",
102
+ "puppeteer": "^22.6.3",
103
103
  "sinon": "^17.0.1",
104
104
  "supertest": "^6.3.4",
105
105
  "types.d.ts": "~0.6.21",
106
- "typescript": "^5.4.3",
106
+ "typescript": "^5.4.4",
107
107
  "why-is-node-running": "^2.2.2"
108
108
  },
109
109
  "engines": {