1 | /*
|
2 |
|
3 | ----------------------------------------------------------------------------
|
4 | | qewd: Quick and Easy Web Development |
|
5 | | |
|
6 | | Copyright (c) 2017 M/Gateway Developments Ltd, |
|
7 | | Reigate, Surrey UK. |
|
8 | | All rights reserved. |
|
9 | | |
|
10 | | http://www.mgateway.com |
|
11 | | Email: rtweed@mgateway.com |
|
12 | | |
|
13 | | |
|
14 | | Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 | | you may not use this file except in compliance with the License. |
|
16 | | You may obtain a copy of the License at |
|
17 | | |
|
18 | | http://www.apache.org/licenses/LICENSE-2.0 |
|
19 | | |
|
20 | | Unless required by applicable law or agreed to in writing, software |
|
21 | | distributed under the License is distributed on an "AS IS" BASIS, |
|
22 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
23 | | See the License for the specific language governing permissions and |
|
24 | | limitations under the License. |
|
25 | ----------------------------------------------------------------------------
|
26 |
|
27 | 3 January 2017
|
28 |
|
29 | */
|
30 |
|
31 | var gtm = require('nodem');
|
32 | var db = new gtm.Gtm();
|
33 | var ok = db.open();
|
34 |
|
35 | var DocumentStore = require('ewd-qoper8-gtm/node_modules/ewd-document-store');
|
36 | var documentStore = new DocumentStore(db);
|
37 |
|
38 | var queue = new documentStore.DocumentNode('ewdQueue');
|
39 | var messages = queue.$('message');
|
40 | var pending = queue.$('pending');
|
41 |
|
42 | var now = new Date().getTime();
|
43 | var diff = process.argv[2];
|
44 | if (!diff) diff = 3600; // default leave 1 hour's worth of records
|
45 |
|
46 | diff = diff * 1000;
|
47 | var cutOff = now - diff;
|
48 |
|
49 | messages.forEachChild(function(dbIndex, messageObj) {
|
50 | var timestamp = parseInt(dbIndex.split('-')[0]);
|
51 | if (timestamp < cutOff) {
|
52 | var token = messageObj.$('token').value;
|
53 | if (!pending.$(token).exists) {
|
54 | messageObj.delete();
|
55 | console.log(dbIndex + ' deleted');
|
56 | }
|
57 | }
|
58 |
|
59 | });
|
60 |
|
61 | db.close();
|