fleetmap-reports 2.0.236 → 2.0.238

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zone-report.js +24 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.236",
3
+ "version": "2.0.238",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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,8 +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 pLimit = (await import('p-limit')).default
89
- const limit = pLimit(50)
110
+ const limit = simpleLimit(50)
90
111
  const promises = sliced.map((slice, i) => limit(async () => {
91
112
  const now = new Date()
92
113
  return traccar.axios.post(url, {
@@ -105,7 +126,7 @@ async function createZoneReport (from, to, userData, traccar) {
105
126
  )
106
127
  const results = await Promise.all(promises)
107
128
  results.forEach(processed => {
108
- if (processed) {
129
+ if (processed && processed.length) {
109
130
  allData.devices.push(...processed)
110
131
  }
111
132
  })