@tmlmobilidade/go-utils-exec 20260829.1122.26 → 20260829.1307.28

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.
@@ -9,6 +9,7 @@ export interface PerformInTimeChunksOptions {
9
9
  endDate?: UnixMilliseconds;
10
10
  intervalHrs: number;
11
11
  onChunk: (chunk: PerformInTimeChunksItem) => Promise<void>;
12
+ order: 'asc' | 'desc';
12
13
  startDate: UnixMilliseconds;
13
14
  }
14
- export declare function performInTimeChunks({ endDate, intervalHrs, onChunk, startDate }: PerformInTimeChunksOptions): Promise<void>;
15
+ export declare function performInTimeChunks({ endDate, intervalHrs, onChunk, order, startDate }: PerformInTimeChunksOptions): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  /* * */
2
2
  import { Dates, splitTimeIntervals } from '@tmlmobilidade/go-utils-dates';
3
- export async function performInTimeChunks({ endDate, intervalHrs, onChunk, startDate }) {
3
+ export async function performInTimeChunks({ endDate, intervalHrs, onChunk, order, startDate }) {
4
4
  //
5
5
  // In order to sync both collections in a manageable way, due to the high volume of data,
6
6
  // it is necessary to divide the process into smaller blocks. Instead of syncing all documents at once,
@@ -8,25 +8,20 @@ export async function performInTimeChunks({ endDate, intervalHrs, onChunk, start
8
8
  // Like this we can more easily compare the IDs in memory and sync only the missing documents.
9
9
  // More recent data is more important than older data, so we start syncing the most recent data first.
10
10
  // It makes sense to divide chunks by day, but this should be adjusted according to the volume of data in each chunk.
11
- const endDateValue = endDate
12
- ? Dates.fromUnixMilliseconds(endDate).unix_milliseconds
13
- : Dates.now('utc').minus({ seconds: 30 }).unix_milliseconds;
14
- const startDateValue = Dates.fromUnixMilliseconds(startDate).unix_milliseconds;
15
- const allTimestampChunks = splitTimeIntervals(startDateValue, endDateValue, intervalHrs);
11
+ const endDateValue = endDate || Dates.now('utc').minus({ seconds: 30 }).unix_milliseconds;
12
+ const allTimestampChunks = splitTimeIntervals(startDate, endDateValue, intervalHrs, order);
16
13
  //
17
14
  // Iterate over each timestamp chunk and sync the documents.
18
15
  // Timestamp chunks are sorted in descending order, so that more recent data is processed first.
19
16
  // Timestamp chunks are in the format { start: day1, end: day2 }, so end is always greater than start.
20
17
  // This might be confusing as the array of chunks itself is sorted in descending order, but the chunks individually are not.
21
18
  for (const [chunkIndex, chunkData] of allTimestampChunks.entries()) {
22
- //
23
- const chunkStartDate = Dates
24
- .fromUnixMilliseconds(chunkData.start)
25
- .setZone('Europe/Lisbon', 'offset_only');
26
- const chunkEndDate = Dates
27
- .fromUnixMilliseconds(chunkData.end)
28
- .setZone('Europe/Lisbon', 'offset_only');
29
- await onChunk({ end: chunkEndDate.unix_milliseconds, index: chunkIndex, start: chunkStartDate.unix_milliseconds, total: allTimestampChunks.length });
19
+ await onChunk({
20
+ end: chunkData.end,
21
+ index: chunkIndex,
22
+ start: chunkData.start,
23
+ total: allTimestampChunks.length,
24
+ });
30
25
  }
31
26
  //
32
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-utils-exec",
3
- "version": "20260829.1122.26",
3
+ "version": "20260829.1307.28",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"