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

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,7 @@ 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
101
  if(!this.rootPath){
102
102
  console.log('ATENCIÓN hay que poner be.rootPath antes de llamar a super()');
103
103
  this.rootPath=Path.resolve(__dirname,'..');
@@ -119,7 +119,7 @@ class AppBackend{
119
119
  this.tableStructures = {};
120
120
  this.configStaticConfig();
121
121
  /** @type {null|()=>Promise<void>} */
122
- this.shootDownBackend = null;
122
+ this.shutdownBackend = null;
123
123
  /** @type {bp.Server} */
124
124
  // @ts-ignore
125
125
  this.server = null;
@@ -406,7 +406,7 @@ function MemoryPerodicallySaved(session){
406
406
  console.log('dumping sessions every',dumpEverySeconds,'seconds');
407
407
  var errorsToShow=4;
408
408
  // TODO: hangs the server in devel mode
409
- setInterval(function(){
409
+ var interval = setInterval(function(){
410
410
  try{
411
411
  fs.writeFile(fileName,json4all.stringify(store.store.dump()));
412
412
  }catch(err){
@@ -417,6 +417,10 @@ function MemoryPerodicallySaved(session){
417
417
  }
418
418
  }
419
419
  },dumpEverySeconds*1000);
420
+ be.shutdownCallbackListAdd({
421
+ message:'session saver',
422
+ fun:()=>clearInterval(interval)
423
+ })
420
424
  });
421
425
  }
422
426
  }
@@ -626,32 +630,36 @@ AppBackend.prototype.start = function start(opts){
626
630
  // @ts-ignore : only for testing */
627
631
  this.getMainApp = function getMainApp(){ return mainApp; };
628
632
  }
629
- this.shootDownBackend = function shootDownBackend(){
633
+ this.shutdownCallbackListAdd = function(messageFun){
634
+ this.shutdownCallbackList.push(messageFun);
635
+ }
636
+ this.shutdownBackend = async function shutdownBackend(){
630
637
  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
- });
638
+ var waitFor = [
639
+ new Promise(function(resolve,reject){
640
+ console.log('*','express server');
641
+ be.server.close(/** @param {Error} err */function(err){
642
+ if(err){
643
+ console.log('*', err)
644
+ reject(err);
645
+ }else{
646
+ console.log('*','express server done!')
647
+ resolve();
648
+ }
649
+ });
650
+ }),
651
+ ...(be.shutdownCallbackList.map(x => (async function(){
652
+ console.log('shut:', x.message)
653
+ await x.fun()
654
+ console.log('done:', x.message)
655
+ })()))
656
+ ];
657
+ console.log('*', 'waiting for all')
658
+ await Promise.all(waitFor);
659
+ console.log('*', 'all done')
660
+ mainApp = null;
661
+ console.log('* logWhy',logWhy)
662
+ logWhy && logWhy();
655
663
  };
656
664
  return Promise.resolve().then(function(){
657
665
  var configList=be.configList();
@@ -963,12 +971,18 @@ AppBackend.prototype.start = function start(opts){
963
971
  loginPlusOpts.noLoggedUrlPath=be.config.login.unloggedLandPage;
964
972
  }
965
973
  mainApp.loginPlusManager.init(mainApp,changing(be.config.login.plus,loginPlusOpts));
966
- be.shootDownCallbackList.push({
974
+ be.shutdownCallbackListAdd({
967
975
  message:'login-plus manager',
968
976
  fun:function(){
969
977
  mainApp.loginPlusManager.closeManager();
970
978
  }
971
979
  });
980
+ be.shutdownCallbackListAdd({
981
+ message:'pg',
982
+ fun:function(){
983
+ pg.shutdown();
984
+ }
985
+ });
972
986
  mainApp.loginPlusManager.setValidatorStrategy(
973
987
  function(req, username, password, done) {
974
988
  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.11",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/backend-plus",