fleetmap-reports 2.0.314 → 2.0.316

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetmap-reports",
3
- "version": "2.0.314",
3
+ "version": "2.0.316",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -12,7 +12,7 @@ function Reports (config, axios) {
12
12
  }
13
13
  this.getUserData = async () => {
14
14
  return {
15
- user: await this.traccar.session.sessionGet().then(d => d.data),
15
+ user: await this.traccar.session.sessionGet(process.env.TOKEN).then(d => d.data),
16
16
  devices: await this.traccar.devices.devicesGet().then(d => d.data),
17
17
  groups: await this.traccar.groups.groupsGet().then(d => d.data),
18
18
  drivers: await this.traccar.drivers.driversGet().then(d => d.data),
@@ -25,12 +25,6 @@ exports.parallel = (report, method, toSlice, ...args) => {
25
25
  try {
26
26
  console.log('forking worker', workerCount++, report, method, slice.length)
27
27
  const worker = cluster.fork()
28
- worker.send({
29
- report,
30
- method,
31
- args: [slice, ...args]
32
- })
33
- console.log('sent to worker', worker.process.pid)
34
28
  worker.on('message', ({ result }) => {
35
29
  console.log('received result from worker', worker.process.pid)
36
30
  _result.push(result)
@@ -48,6 +42,12 @@ exports.parallel = (report, method, toSlice, ...args) => {
48
42
  reject(new Error(`Worker ${worker.process.pid} exited with code ${code} and signal ${signal}`))
49
43
  }
50
44
  })
45
+ worker.send({
46
+ report,
47
+ method,
48
+ args: [slice, ...args]
49
+ })
50
+ console.log('sent to worker', worker.process.pid)
51
51
  } catch (e) {
52
52
  console.error(report, method, 'worker', workerCount, 'numCPUs', numCPUs)
53
53
  reject(e)
@@ -4,9 +4,19 @@ const { streamArray } = require('stream-json/streamers/StreamArray')
4
4
  const { Readable } = require('stream')
5
5
  const { cleanPosition, filterPosition } = require('./route')
6
6
 
7
+ function fetchRetry (url, options, retry = 3) {
8
+ return fetch(url, options).catch(async e => {
9
+ if (retry) {
10
+ console.warn(url, e.message, 'retrying', retry)
11
+ return fetchRetry(url, options, retry - 1)
12
+ }
13
+ throw e
14
+ })
15
+ }
16
+
7
17
  module.exports = async ({ url, cookie, filter }) => {
8
18
  const now = new Date()
9
- const response = await fetch(url, { headers: { cookie } })
19
+ const response = await fetchRetry(url, { headers: { cookie } })
10
20
  .catch(e => {
11
21
  console.error(e)
12
22
  throw new Error(`${e.message} traccar-worker ${cookie} ${url}`)
@@ -150,7 +150,6 @@ async function createZoneReport (from, to, userData, traccar) {
150
150
 
151
151
  async function processDevices (from, to, devices, userData, data) {
152
152
  const devicesResult = []
153
- console.log('processDevices', from, to, devices.length)
154
153
  for (const d of devices) {
155
154
  const alerts = data.alerts.filter(t => t && t.deviceId === d.id)
156
155
  const deviceRoute = data.route.filter(p => p.deviceId === d.id)
@@ -538,7 +537,7 @@ function analyseAlerts (alerts, deviceRoute, userData, from, to, device) {
538
537
 
539
538
  async function getInAndOutEvents (devices, route, userData) {
540
539
  const events = []
541
- const geofencesFeatures = userData.geofences.map(g => convertToFeature(g))
540
+ const geofencesFeatures = userData.geofences.filter(g => g.area).map(g => convertToFeature(g))
542
541
  devices.forEach(d => {
543
542
  const deviceRoute = route.filter(p => p.deviceId === d.id)
544
543
  const routePoints = deviceRoute.sort(sortPositions).map(p => convertPositionToFeature(p))