fleetmap-reports 2.0.230 → 2.0.232
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/package.json +2 -1
- package/src/zone-report.js +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetmap-reports",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.232",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"jspdf": "^2.5.1",
|
|
24
24
|
"jspdf-autotable": "3.8.1",
|
|
25
25
|
"moment": "2.30.1",
|
|
26
|
+
"p-limit": "^6.2.0",
|
|
26
27
|
"piscina": "^4.9.2",
|
|
27
28
|
"stream-chain": "^3.4.0",
|
|
28
29
|
"stream-json": "^1.9.1",
|
package/src/zone-report.js
CHANGED
|
@@ -25,6 +25,8 @@ const axios = require('axios').default
|
|
|
25
25
|
const sliceSize = 1
|
|
26
26
|
const deviceChunk = 5
|
|
27
27
|
const fileName = 'ZoneReport'
|
|
28
|
+
const {pLimit} = require('p-limit')
|
|
29
|
+
|
|
28
30
|
|
|
29
31
|
exports.process = async (traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData) => {
|
|
30
32
|
const data = await traccarHelper.getAllInOne(
|
|
@@ -83,23 +85,22 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
83
85
|
const reportRangeDays = (new Date(to).getTime() - new Date(from).getTime()) / (1000 * 60 * 60 * 24)
|
|
84
86
|
const sliced = automaticReports.sliceArray(devices, sliceSize)
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
const url = `https://${process.env.SERVER_HOST}/pinmeapi/process-report/zone-report-processing`
|
|
88
|
+
const url = 'https://api.pinme.io/pinmeapi/process-report/zone-report-processing'
|
|
88
89
|
|
|
89
|
-
const promises = sliced.map(slice => {
|
|
90
|
+
const promises = sliced.map((slice, i) => {
|
|
90
91
|
const now = new Date()
|
|
91
92
|
return traccar.axios.post(url, {
|
|
92
93
|
from,
|
|
93
94
|
to,
|
|
94
95
|
userData,
|
|
95
96
|
slice,
|
|
96
|
-
deviceCount:
|
|
97
|
+
deviceCount: i,
|
|
97
98
|
devices,
|
|
98
99
|
reportRangeDays
|
|
99
100
|
}, { timeout: 900000 }).then(response => {
|
|
100
101
|
console.log('processed devices', slice.map(d => d.id), 'in', new Date() - now, 'ms')
|
|
101
102
|
return response.data
|
|
102
|
-
}).catch(e => console.error(e.message, e
|
|
103
|
+
}).catch(e => console.error(url, e.message, e))
|
|
103
104
|
})
|
|
104
105
|
const results = await Promise.all(promises)
|
|
105
106
|
results.forEach(processed => {
|