@autofleet/node-common 1.1.65 → 1.1.66
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/.circleci/config.yml +1 -1
- package/.gitlab-ci.yml +1 -1
- package/README.md +8 -0
- package/events/index.js +9 -38
- package/package.json +6 -5
- package/settings/map.js +14 -0
package/.circleci/config.yml
CHANGED
package/.gitlab-ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -49,6 +49,14 @@ To learn more [click here](https://blog.risingstack.com/designing-microservices-
|
|
|
49
49
|
|
|
50
50
|
## Settings
|
|
51
51
|
|
|
52
|
+
### Adding settings
|
|
53
|
+
For adding new setting you need to add it to the map.js file, please specify
|
|
54
|
+
* name - descriptive name
|
|
55
|
+
* description - few words about what it does + unit
|
|
56
|
+
* type - supportable types: 'number', 'string', 'json'
|
|
57
|
+
* defaultValue - default value
|
|
58
|
+
* context - 'security' and 'operation' will not show in the simulator configuration
|
|
59
|
+
|
|
52
60
|
See example.
|
|
53
61
|
|
|
54
62
|
## DeLorean
|
package/events/index.js
CHANGED
|
@@ -1,52 +1,21 @@
|
|
|
1
1
|
const PubSub = require('@google-cloud/pubsub');
|
|
2
2
|
const logger = require('../logger/index')();
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const getPubsubPublisher = async () => {
|
|
8
|
-
if (Publisher) {
|
|
9
|
-
return Publisher;
|
|
10
|
-
}
|
|
11
|
-
|
|
4
|
+
// EventType - 'vehicle'/'stop_point' etc.
|
|
5
|
+
const publish = (eventType, eventObj, debug = false) => {
|
|
12
6
|
const envv = process.env.NODE_ENV || 'development';
|
|
13
7
|
const projectId = process.env.PROJECT;
|
|
14
8
|
const topic = process.env.TOPIC;
|
|
15
9
|
|
|
16
10
|
if (!topic || !projectId) {
|
|
17
|
-
return
|
|
18
|
-
debug: 'Missing project/topic',
|
|
19
|
-
};
|
|
11
|
+
return 'Missing project/topic';
|
|
20
12
|
}
|
|
21
13
|
|
|
22
|
-
if ((envv === 'development' || envv === 'test')) {
|
|
23
|
-
return
|
|
24
|
-
debug: 'Not publishing in dev/test',
|
|
25
|
-
};
|
|
14
|
+
if ((envv === 'development' || envv === 'test') && !debug) {
|
|
15
|
+
return 'Not publishing in dev/test';
|
|
26
16
|
}
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
Publisher = Client.topic(topic).publisher();
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
client: Client,
|
|
33
|
-
publisher: Publisher,
|
|
34
|
-
topic,
|
|
35
|
-
envv,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// EventType - 'vehicle'/'stop_point' etc.
|
|
40
|
-
const publish = (eventType, eventObj) => {
|
|
41
|
-
const {
|
|
42
|
-
debug,
|
|
43
|
-
publisher,
|
|
44
|
-
envv,
|
|
45
|
-
} = getPubsubPublisher();
|
|
46
|
-
|
|
47
|
-
if (debug) {
|
|
48
|
-
return debug;
|
|
49
|
-
}
|
|
18
|
+
const pubsubClient = new PubSub({ projectId });
|
|
50
19
|
|
|
51
20
|
const msg = {
|
|
52
21
|
type: eventType,
|
|
@@ -57,7 +26,9 @@ const publish = (eventType, eventObj) => {
|
|
|
57
26
|
const data = JSON.stringify(msg);
|
|
58
27
|
const dataBuffer = Buffer.from(data);
|
|
59
28
|
|
|
60
|
-
return
|
|
29
|
+
return pubsubClient
|
|
30
|
+
.topic(topic)
|
|
31
|
+
.publisher()
|
|
61
32
|
.publish(dataBuffer)
|
|
62
33
|
.then((messageId) => {
|
|
63
34
|
logger.info(`Message ${messageId} published to google pubsub`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/node-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"coverage": "jest --coverage --forceExit --runInBand",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"linter": "./node_modules/.bin/eslint ."
|
|
10
10
|
},
|
|
11
11
|
"jest": {
|
|
12
|
-
"setupTestFrameworkScriptFile": "jest-extended"
|
|
12
|
+
"setupTestFrameworkScriptFile": "jest-extended",
|
|
13
|
+
"testURL": "http://localhost:8085/"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
15
16
|
"type": "git",
|
|
@@ -18,9 +19,9 @@
|
|
|
18
19
|
"author": "",
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"bugs": {
|
|
21
|
-
"url": "https://
|
|
22
|
+
"url": "https://github.com/Autofleet/node-common/issues"
|
|
22
23
|
},
|
|
23
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://github.com/Autofleet/node-common",
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"@google-cloud/logging-winston": "^0.10.2",
|
|
26
27
|
"@google-cloud/pubsub": "^0.20.1",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"dotenv": "^5.0.1",
|
|
30
31
|
"event-pubsub": "^4.3.0",
|
|
31
32
|
"express": "^4.16.2",
|
|
32
|
-
"jest": "^22.4.
|
|
33
|
+
"jest": "^22.4.4",
|
|
33
34
|
"mock-socket": "^7.1.0",
|
|
34
35
|
"node-cache": "^4.2.0",
|
|
35
36
|
"node-resque": "^5.4.1",
|
package/settings/map.js
CHANGED
|
@@ -262,4 +262,18 @@ module.exports = {
|
|
|
262
262
|
defaultValue: 5,
|
|
263
263
|
context: 'security',
|
|
264
264
|
},
|
|
265
|
+
MAXIMUM_RADIUS_FOR_STOP_POINT_UPDATE: {
|
|
266
|
+
name: 'Maximum radius for stoppoint update',
|
|
267
|
+
description: 'The maximum radius (in meters) that a stop point can be updated to',
|
|
268
|
+
type: 'number',
|
|
269
|
+
defaultValue: 1000,
|
|
270
|
+
context: 'operation',
|
|
271
|
+
},
|
|
272
|
+
DEMAND_PREDICTION_TIMEFRAMES: {
|
|
273
|
+
name: 'Demand prediction time frames',
|
|
274
|
+
description: 'Demand prediction time frames for fleet',
|
|
275
|
+
type: 'json',
|
|
276
|
+
defaultValue: '["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"]',
|
|
277
|
+
context: 'demand prediction',
|
|
278
|
+
},
|
|
265
279
|
};
|