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.
@@ -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.2')
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
- await handle_inbox(box,options);
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();
@@ -4,7 +4,7 @@ const { moveTo } = require('../lib/util');
4
4
 
5
5
  async function handle(path,options) {
6
6
  logger.info(`parsing notification ${path}`);
7
-
7
+
8
8
  try {
9
9
  const json = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8'}));
10
10
 
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
- console.log(glob);
20
- fs.readdir(path, (err,files) => {
21
- files.forEach( (file) => {
22
- const fullPath = `${path}/${file}`;
23
- console.log(file);
24
- if (file.match(glob)) {
25
- // Process
26
- lockfile.lock(fullPath)
27
- .then( async (release) => {
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
- return release();
30
- })
31
- .catch( (e) => {
35
+ }
36
+ catch (e) {
32
37
  logger.error(e);
33
- logger.warn(`${fullPath} is locked`);
34
- })
35
- .finally( () => {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldn-inbox-server",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "A demonstration Event Notifications Inbox server",
5
5
  "main": "lib/index.js",
6
6
  "author": "Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>",