fleetmap-reports 2.0.236 → 2.0.237
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 +1 -1
- package/src/zone-report.js +23 -3
package/package.json
CHANGED
package/src/zone-report.js
CHANGED
|
@@ -26,6 +26,28 @@ const sliceSize = 1
|
|
|
26
26
|
const deviceChunk = 5
|
|
27
27
|
const fileName = 'ZoneReport'
|
|
28
28
|
|
|
29
|
+
function simpleLimit (concurrency) {
|
|
30
|
+
const queue = []
|
|
31
|
+
let activeCount = 0
|
|
32
|
+
|
|
33
|
+
const next = () => {
|
|
34
|
+
if (queue.length === 0 || activeCount >= concurrency) return
|
|
35
|
+
activeCount++
|
|
36
|
+
const { fn, resolve, reject } = queue.shift()
|
|
37
|
+
fn().then(resolve).catch(reject).finally(() => {
|
|
38
|
+
activeCount--
|
|
39
|
+
next()
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return fn => {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
queue.push({ fn, resolve, reject })
|
|
46
|
+
next()
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
29
51
|
exports.process = async (traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData) => {
|
|
30
52
|
const data = await traccarHelper.getAllInOne(
|
|
31
53
|
traccar, from, to, slice, true, false, false, false,
|
|
@@ -85,9 +107,7 @@ async function createZoneReport (from, to, userData, traccar) {
|
|
|
85
107
|
|
|
86
108
|
const url = 'https://api.pinme.io/pinmeapi/process-report/zone-report-processing'
|
|
87
109
|
|
|
88
|
-
const
|
|
89
|
-
const limit = pLimit(50)
|
|
90
|
-
const promises = sliced.map((slice, i) => limit(async () => {
|
|
110
|
+
const promises = sliced.map((slice, i) => simpleLimit(async () => {
|
|
91
111
|
const now = new Date()
|
|
92
112
|
return traccar.axios.post(url, {
|
|
93
113
|
from,
|