(
job: QueueJob,
items: any[],
dataType: string,
)
| 415 | } |
| 416 | |
| 417 | private createWorkChunks( |
| 418 | job: QueueJob, |
| 419 | items: any[], |
| 420 | dataType: string, |
| 421 | ): void { |
| 422 | if (!job.allocatedWorkers || !items.length) return; |
| 423 | |
| 424 | const chunkSize = Math.ceil(items.length / job.allocatedWorkers); |
| 425 | |
| 426 | const existingJob = activeJobs.get(job.id); |
| 427 | if (existingJob) { |
| 428 | updateJob(existingJob, { |
| 429 | status: ImportStatus.ProcessingHeartbeats, |
| 430 | current: 0, |
| 431 | total: items.length, |
| 432 | }); |
| 433 | } |
| 434 | |
| 435 | this.completedChunks.set(job.id, new Set()); |
| 436 | |
| 437 | for (let i = 0; i < job.allocatedWorkers; i++) { |
| 438 | const start = i * chunkSize; |
| 439 | const end = Math.min(start + chunkSize, items.length); |
| 440 | |
| 441 | if (start < items.length) { |
| 442 | const chunk: WorkChunk = { |
| 443 | id: `${job.id}-chunk-${i}`, |
| 444 | jobId: job.id, |
| 445 | type: "date-range", |
| 446 | data: |
| 447 | dataType === "wakapi" |
| 448 | ? { |
| 449 | dates: items.slice(start, end), |
| 450 | heartbeatsByDate: job.data.heartbeatsByDate, |
| 451 | chunkIndex: i, |
| 452 | totalChunks: job.allocatedWorkers, |
| 453 | originalJob: job, |
| 454 | processedDays: 0, |
| 455 | } |
| 456 | : { |
| 457 | days: items.slice(start, end), |
| 458 | chunkIndex: i, |
| 459 | totalChunks: job.allocatedWorkers, |
| 460 | originalJob: job, |
| 461 | processedDays: 0, |
| 462 | }, |
| 463 | status: "pending", |
| 464 | progress: 0, |
| 465 | }; |
| 466 | |
| 467 | this.workChunks.set(chunk.id, chunk); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | private async processWorkChunk( |
| 473 | chunk: WorkChunk, |
no test coverage detected