ldn-inbox-server 1.8.2 → 1.8.3

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.
@@ -27,7 +27,7 @@
27
27
  },
28
28
  {
29
29
  "id": "@handler/notification_handler/offer_memento.js",
30
- "$sequential": true,
30
+ "$lock": true,
31
31
  "actor": {
32
32
  "id": "http://localhost:8000/profile/card#me" ,
33
33
  "inbox": "http://localhost:8000/inbox/" ,
@@ -13,8 +13,8 @@ const md5 = require('md5');
13
13
  * need to run on an notifiction message. The inner array defines the steps: a
14
14
  * sequence of handlers that need to success.
15
15
  *
16
- * Optionally a configuration for a handler can contain the property `$sequential` set
17
- * to true to force the sequential execution of this handler.
16
+ * Optionally a configuration for a handler can contain the property `$lock` set
17
+ * to true to force the singular execution of this handler.
18
18
  */
19
19
  async function handle({path,options,_,notification}) {
20
20
  let success = false;
@@ -70,7 +70,11 @@ async function handle({path,options,_,notification}) {
70
70
  return await handler({path,options,config,notification});
71
71
  });
72
72
 
73
- if (result['break']) {
73
+ if (! result) {
74
+ logger.error(`workflow[${i}] : failed ${step} (no results)`);
75
+ thisWorkflow = result['failure'];
76
+ }
77
+ else if (result['break']) {
74
78
  logger.info(`workflow[${i}] : breaks ${step} with ${result['success']}`);
75
79
  thisWorkflow = result['success'];
76
80
  }
@@ -140,8 +144,10 @@ async function handle({path,options,_,notification}) {
140
144
  }
141
145
 
142
146
  async function maybeLock(step,config,callback) {
143
- if (config['$sequential']) {
144
- const lockDir = process.env.LDN_SERVER_LOCKDIR || '.lockdir';
147
+ if (config['$lock']) {
148
+ const lockDir = process.env.LDN_SERVER_LOCK_DIR || '.lockdir';
149
+ const lockStale = process.env.LDN_SERVER_LOCK_STALE || 10000;
150
+ const lockRetries = process.env.LDN_SERVER_LOCK_RETRIES || 10;
145
151
 
146
152
  if (! fs.existsSync(lockDir)) {
147
153
  logger.debug(`creating lock dir ${lockDir}`);
@@ -155,15 +161,22 @@ async function maybeLock(step,config,callback) {
155
161
  fs.writeFileSync(lockFile,'');
156
162
  }
157
163
 
158
- logger.debug(`locking ${step} using ${lockFile}`);
164
+ let result = null;
165
+
166
+ try {
167
+ logger.debug(`locking ${step} using ${lockFile}`);
159
168
 
160
- const unlock = await lockfile.lock(lockFile);
169
+ const unlock = await lockfile.lock(lockFile, { stale : lockStale , retries: lockRetries });
161
170
 
162
- const result = await callback();
171
+ result = await callback();
163
172
 
164
- logger.debug(`unlocking ${step} from ${lockFile}`);
173
+ logger.debug(`unlocking ${step} from ${lockFile}`);
165
174
 
166
- unlock();
175
+ unlock();
176
+ }
177
+ catch (e) {
178
+ logger.error(`lock failed: ${e.message}`);
179
+ }
167
180
 
168
181
  return result;
169
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldn-inbox-server",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "A demonstration Event Notifications Inbox server",
5
5
  "main": "lib/index.js",
6
6
  "author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",