fleetmap-reports 2.0.235 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zone-report.js +23 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.235",
3
+ "version": "2.0.237",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -25,8 +25,28 @@ const axios = require('axios').default
25
25
  const sliceSize = 1
26
26
  const deviceChunk = 5
27
27
  const fileName = 'ZoneReport'
28
- const pLimit = (await import('p-limit')).default
29
- const limit = pLimit(50)
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
+ }
30
50
 
31
51
  exports.process = async (traccar, from, to, slice, deviceCount, devices, reportRangeDays, userData) => {
32
52
  const data = await traccarHelper.getAllInOne(
@@ -87,7 +107,7 @@ async function createZoneReport (from, to, userData, traccar) {
87
107
 
88
108
  const url = 'https://api.pinme.io/pinmeapi/process-report/zone-report-processing'
89
109
 
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,