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.
package/config/inbox_config.json
CHANGED
|
@@ -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 `$
|
|
17
|
-
* to true to force the
|
|
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
|
|
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['$
|
|
144
|
-
const lockDir = process.env.
|
|
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
|
-
|
|
164
|
+
let result = null;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
logger.debug(`locking ${step} using ${lockFile}`);
|
|
159
168
|
|
|
160
|
-
|
|
169
|
+
const unlock = await lockfile.lock(lockFile, { stale : lockStale , retries: lockRetries });
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
result = await callback();
|
|
163
172
|
|
|
164
|
-
|
|
173
|
+
logger.debug(`unlocking ${step} from ${lockFile}`);
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
unlock();
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
logger.error(`lock failed: ${e.message}`);
|
|
179
|
+
}
|
|
167
180
|
|
|
168
181
|
return result;
|
|
169
182
|
}
|