ldn-inbox-server 1.1.2 → 1.1.4
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/bin/ldn-inbox-server.js +11 -2
- package/handler/demo_notification_handler.js +1 -1
- package/lib/handler.js +30 -19
- package/package.json +1 -1
package/bin/ldn-inbox-server.js
CHANGED
|
@@ -17,7 +17,7 @@ const JSON_SCHEMA_PATH = process.env.LDN_SERVER_JSON_SCHEMA ?? './config/notific
|
|
|
17
17
|
|
|
18
18
|
program
|
|
19
19
|
.name('lnd-inbox-server')
|
|
20
|
-
.version('1.1.
|
|
20
|
+
.version('1.1.4')
|
|
21
21
|
.description('A demonstration Event Notifications Inbox server');
|
|
22
22
|
|
|
23
23
|
program
|
|
@@ -35,6 +35,7 @@ program
|
|
|
35
35
|
|
|
36
36
|
program
|
|
37
37
|
.command('handler')
|
|
38
|
+
.option('--loop <seconds>', 'run in a loop',0)
|
|
38
39
|
.option('--inbox <inbox>','inbox',INBOX_PATH)
|
|
39
40
|
.option('--outbox <outbox>','outbox',OUTBOX_PATH)
|
|
40
41
|
.option('--error <errbox>','errbox',ERROR_PATH)
|
|
@@ -53,7 +54,15 @@ program
|
|
|
53
54
|
options['notification_handler'] ?? defaultSendNotificationHandler;
|
|
54
55
|
break;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
if (options['loop']) {
|
|
58
|
+
while(1) {
|
|
59
|
+
await handle_inbox(box,options);
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, options['loop']*1000));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
await handle_inbox(box,options);
|
|
65
|
+
}
|
|
57
66
|
});
|
|
58
67
|
|
|
59
68
|
program.parse();
|
package/lib/handler.js
CHANGED
|
@@ -16,29 +16,40 @@ async function defaultInboxHandler(path,options) {
|
|
|
16
16
|
|
|
17
17
|
const glob = new RegExp(options['glob'] ?? "^.*\\.jsonld$");
|
|
18
18
|
const handler = dynamic_handler(options['notification_handler'],null);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
|
|
20
|
+
// Need some more elegant code here to select of batch of files to
|
|
21
|
+
// process in the path. The code below will work as long as the
|
|
22
|
+
// number of files in the inbox don't become gigantic...
|
|
23
|
+
const files = fs.readdirSync(path);
|
|
24
|
+
|
|
25
|
+
for (let i = 0 ; i < files.length ; i++) {
|
|
26
|
+
const file = files[i];
|
|
27
|
+
const fullPath = `${path}/${file}`;
|
|
28
|
+
|
|
29
|
+
if (file.match(glob)) {
|
|
30
|
+
// Process
|
|
31
|
+
lockfile.lock(fullPath)
|
|
32
|
+
.then( async (release) => {
|
|
33
|
+
try {
|
|
28
34
|
await handler(fullPath,options);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.catch( (e) => {
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
32
37
|
logger.error(e);
|
|
33
|
-
logger.
|
|
34
|
-
}
|
|
35
|
-
|
|
38
|
+
logger.error(`handler failed on ${fullPath}`);
|
|
39
|
+
}
|
|
40
|
+
return release();
|
|
41
|
+
})
|
|
42
|
+
.catch( (e) => {
|
|
43
|
+
logger.debug(`${fullPath} is locked`);
|
|
44
|
+
})
|
|
45
|
+
.finally( () => {
|
|
46
|
+
if (fs.existsSync(fullPath)) {
|
|
36
47
|
logger.debug(`removing ${fullPath}`);
|
|
37
48
|
fs.unlinkSync(fullPath);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
async function defaultSendNotificationHandler(path,options) {
|