@cldmv/holdmytask 1.4.0 → 1.5.0

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/README.md CHANGED
@@ -480,6 +480,102 @@ const groupInfo = queue.getCoalescingGroup("user-action");
480
480
  const taskGroup = queue.findCoalescingGroupByTaskId(task1.id);
481
481
  ```
482
482
 
483
+ ### Debug and Inspection Methods
484
+
485
+ For debugging queue behavior, troubleshooting scheduler issues, or monitoring queue state in production, HoldMyTask provides comprehensive inspection methods:
486
+
487
+ #### Quick Debug Output
488
+
489
+ ```javascript
490
+ // Log comprehensive queue state to console
491
+ queue.debugLog(); // Basic summary
492
+ queue.debugLog(true); // Detailed task information
493
+
494
+ // Example output:
495
+ // === HoldMyTask Debug Information ===
496
+ // Timestamp: 2025-11-14T17:45:32.123Z
497
+ // Status: ACTIVE
498
+ // Smart Scheduling: ON
499
+ // Concurrency: 2/5
500
+ //
501
+ // --- Queue State ---
502
+ // Total Tasks: 7
503
+ // Pending: 3
504
+ // Ready: 2
505
+ // Running: 2
506
+ //
507
+ // --- Timer State ---
508
+ // Interval: None
509
+ // Timeout: Active (15)
510
+ // Next Run: 1250ms
511
+ ```
512
+
513
+ #### Detailed Inspection
514
+
515
+ ```javascript
516
+ // Get comprehensive queue state
517
+ const state = queue.inspect();
518
+ console.log("Total tasks:", state.totals.totalTasks);
519
+ console.log("Running tasks:", state.queues.running.tasks);
520
+ console.log("Next scheduled run:", state.timers.nextRunIn, "ms");
521
+
522
+ // Inspect just the tasks
523
+ const tasks = queue.inspectTasks();
524
+ console.log("Tasks by priority:", tasks.byPriority);
525
+ console.log("Tasks by coalescing key:", tasks.byCoalescingKey);
526
+
527
+ // Inspect scheduler state
528
+ const scheduler = queue.inspectScheduler();
529
+ console.log("Can run task now:", scheduler.nextTask?.canRunNow);
530
+ console.log("Available slots:", scheduler.availableSlots);
531
+ console.log("Active delays:", scheduler.delays.count);
532
+
533
+ // Inspect timers specifically
534
+ const timers = queue.inspectTimers();
535
+ console.log("Scheduler interval active:", timers.schedulerInterval.active);
536
+ console.log("Next run in:", timers.nextRunIn, "ms");
537
+ ```
538
+
539
+ #### Inspection Methods
540
+
541
+ - `inspect()` - Get comprehensive queue state including tasks, timers, scheduler, and coalescing information
542
+ - `inspectTasks()` - Get detailed task information grouped by status, priority, and coalescing key
543
+ - `inspectScheduler()` - Get scheduler state, timing information, and next task details
544
+ - `inspectTimers()` - Get timer state and scheduling information
545
+ - `debugLog(detailed?)` - Log formatted debug information to console
546
+
547
+ **Use Cases:**
548
+
549
+ - **Development**: Debug why tasks aren't running or understand queue behavior
550
+ - **Production Monitoring**: Track queue health and performance metrics
551
+ - **Troubleshooting**: Identify scheduler issues, timer problems, or concurrency bottlenecks
552
+ - **Testing**: Verify queue state in automated tests
553
+
554
+ ```javascript
555
+ // Example: Debug scheduler restart issue
556
+ const queue = new HoldMyTask({ concurrency: 2 });
557
+
558
+ // Add some tasks
559
+ queue.enqueue(async () => "task1");
560
+ queue.enqueue(async () => "task2", { priority: 2, start: 5000 });
561
+
562
+ // Check initial state
563
+ console.log("Initial state:");
564
+ queue.debugLog();
565
+
566
+ // Wait for drain
567
+ queue.on("drain", () => {
568
+ console.log("After drain:");
569
+ queue.debugLog();
570
+
571
+ // Add new task
572
+ queue.enqueue(async () => "task3");
573
+
574
+ console.log("After adding new task:");
575
+ queue.debugLog();
576
+ });
577
+ ```
578
+
483
579
  ### Events
484
580
 
485
581
  ```javascript
@@ -1141,13 +1141,15 @@ export class HoldMyTask extends EventEmitter {
1141
1141
  return null;
1142
1142
  }
1143
1143
  const groupInfo = this.findCoalescingGroupByTaskId(item.id);
1144
- return groupInfo ? {
1145
- coalescingKey: groupInfo.coalescingKey,
1146
- groupId: groupInfo.groupId,
1147
- representativeId: groupInfo.representativeId,
1148
- taskCount: groupInfo.groupTasks.length,
1149
- allTaskMetadata: groupInfo.groupTasks.map(t => ({ id: t.id, metadata: t.metadata }))
1150
- } : null;
1144
+ return groupInfo
1145
+ ? {
1146
+ coalescingKey: groupInfo.coalescingKey,
1147
+ groupId: groupInfo.groupId,
1148
+ representativeId: groupInfo.representativeId,
1149
+ taskCount: groupInfo.groupTasks.length,
1150
+ allTaskMetadata: groupInfo.groupTasks.map((t) => ({ id: t.id, metadata: t.metadata }))
1151
+ }
1152
+ : null;
1151
1153
  }
1152
1154
  };
1153
1155
 
@@ -1198,13 +1200,15 @@ export class HoldMyTask extends EventEmitter {
1198
1200
  return null;
1199
1201
  }
1200
1202
  const groupInfo = this.findCoalescingGroupByTaskId(item.id);
1201
- return groupInfo ? {
1202
- coalescingKey: groupInfo.coalescingKey,
1203
- groupId: groupInfo.groupId,
1204
- representativeId: groupInfo.representativeId,
1205
- taskCount: groupInfo.groupTasks.length,
1206
- allTaskMetadata: groupInfo.groupTasks.map(t => ({ id: t.id, metadata: t.metadata }))
1207
- } : null;
1203
+ return groupInfo
1204
+ ? {
1205
+ coalescingKey: groupInfo.coalescingKey,
1206
+ groupId: groupInfo.groupId,
1207
+ representativeId: groupInfo.representativeId,
1208
+ taskCount: groupInfo.groupTasks.length,
1209
+ allTaskMetadata: groupInfo.groupTasks.map((t) => ({ id: t.id, metadata: t.metadata }))
1210
+ }
1211
+ : null;
1208
1212
  },
1209
1213
  enumerable: true
1210
1214
  });
@@ -1397,11 +1401,11 @@ export class HoldMyTask extends EventEmitter {
1397
1401
  * @example
1398
1402
  * // Get all groups for a coalescing key
1399
1403
  * const groups = queue.getCoalescingGroup('ui.update');
1400
- *
1404
+ *
1401
1405
  * // Get specific group by ID
1402
1406
  * const group = queue.getCoalescingGroup('ui.update', '1');
1403
1407
  * console.log(group.tasks.size); // Number of tasks in group
1404
- *
1408
+ *
1405
1409
  * // Access individual task metadata
1406
1410
  * for (const [taskId, task] of group.tasks) {
1407
1411
  * console.log(`Task ${taskId}:`, task.metadata);
@@ -1415,7 +1419,7 @@ export class HoldMyTask extends EventEmitter {
1415
1419
 
1416
1420
  if (groupId === null) {
1417
1421
  // Return all groups for the key
1418
- return groups.map(group => ({
1422
+ return groups.map((group) => ({
1419
1423
  coalescingKey: group.coalescingKey,
1420
1424
  groupId: group.groupId,
1421
1425
  representativeId: group.representativeId,
@@ -1434,7 +1438,7 @@ export class HoldMyTask extends EventEmitter {
1434
1438
  }
1435
1439
 
1436
1440
  // Find specific group by ID
1437
- const group = groups.find(g => g.groupId === groupId);
1441
+ const group = groups.find((g) => g.groupId === groupId);
1438
1442
  if (!group) {
1439
1443
  return null;
1440
1444
  }
@@ -1465,10 +1469,10 @@ export class HoldMyTask extends EventEmitter {
1465
1469
  * @example
1466
1470
  * // Get metadata from all groups for a key
1467
1471
  * const allMetadata = queue.getCoalescingGroupMetadata('ui.update');
1468
- *
1472
+ *
1469
1473
  * // Get metadata from specific group
1470
1474
  * const groupMetadata = queue.getCoalescingGroupMetadata('ui.update', '1');
1471
- *
1475
+ *
1472
1476
  * // Example output:
1473
1477
  * // [
1474
1478
  * // { taskId: '123', metadata: { userId: 100, action: 'save' } },
@@ -1481,7 +1485,7 @@ export class HoldMyTask extends EventEmitter {
1481
1485
  return [];
1482
1486
  }
1483
1487
 
1484
- const targetGroups = groupId ? groups.filter(g => g.groupId === groupId) : groups;
1488
+ const targetGroups = groupId ? groups.filter((g) => g.groupId === groupId) : groups;
1485
1489
  const metadata = [];
1486
1490
 
1487
1491
  for (const group of targetGroups) {
@@ -2362,4 +2366,396 @@ export class HoldMyTask extends EventEmitter {
2362
2366
  hasTask(id) {
2363
2367
  return this.has(id);
2364
2368
  }
2369
+
2370
+ // ========================================================================================
2371
+ // DEBUG AND INSPECTION METHODS
2372
+ // ========================================================================================
2373
+
2374
+ /**
2375
+ * Get detailed information about the current queue state for debugging.
2376
+ * @returns {Object} Comprehensive queue state information
2377
+ */
2378
+ inspect() {
2379
+ const now = this.now();
2380
+
2381
+ // Get all tasks from different queues
2382
+ const pendingTasks = [...this.pendingHeap.heap].map((task) => ({
2383
+ id: task.id,
2384
+ priority: task.priority,
2385
+ readyAt: task.readyAt,
2386
+ readyIn: task.readyAt - now,
2387
+ coalescingKey: task.coalescingKey,
2388
+ metadata: task.metadata,
2389
+ status: "pending"
2390
+ }));
2391
+
2392
+ const readyTasks = [...this.readyHeap.heap].map((task) => ({
2393
+ id: task.id,
2394
+ priority: task.priority,
2395
+ coalescingKey: task.coalescingKey,
2396
+ metadata: task.metadata,
2397
+ status: "ready"
2398
+ }));
2399
+
2400
+ const runningTasks = Array.from(this.running).map((task) => ({
2401
+ id: task.id,
2402
+ priority: task.priority,
2403
+ coalescingKey: task.coalescingKey,
2404
+ metadata: task.metadata,
2405
+ startedAt: task.startedAt,
2406
+ runningFor: now - task.startedAt,
2407
+ status: "running"
2408
+ }));
2409
+
2410
+ // Get timer information
2411
+ const timerInfo = this.inspectTimers();
2412
+
2413
+ // Get scheduler state
2414
+ const schedulerState = {
2415
+ isActive: this.isActive,
2416
+ isPaused: !this.isActive,
2417
+ smartScheduling: this.options.smartScheduling,
2418
+ concurrency: this.options.concurrency,
2419
+ currentConcurrency: this.running.size,
2420
+ tick: this.options.tick,
2421
+ nextActiveDelay: this.nextAvailableTime > now ? this.nextAvailableTime - now : null
2422
+ };
2423
+
2424
+ // Get coalescing information
2425
+ const coalescingInfo = {};
2426
+ for (const [key, groups] of this.coalescingGroups.entries()) {
2427
+ coalescingInfo[key] = {
2428
+ groupCount: groups.size,
2429
+ totalTasks: Array.from(groups.values()).reduce((sum, group) => sum + group.tasks.size, 0),
2430
+ groups: Array.from(groups.entries()).map(([groupId, group]) => ({
2431
+ groupId,
2432
+ taskCount: group.tasks.size,
2433
+ representativeId: group.representativeId,
2434
+ tasks: Array.from(group.tasks.entries()).map(([_, task]) => ({
2435
+ id: task.id,
2436
+ metadata: task.metadata
2437
+ }))
2438
+ }))
2439
+ };
2440
+ }
2441
+
2442
+ return {
2443
+ timestamp: now,
2444
+ scheduler: schedulerState,
2445
+ timers: timerInfo,
2446
+ queues: {
2447
+ pending: {
2448
+ count: pendingTasks.length,
2449
+ tasks: pendingTasks
2450
+ },
2451
+ ready: {
2452
+ count: readyTasks.length,
2453
+ tasks: readyTasks
2454
+ },
2455
+ running: {
2456
+ count: runningTasks.length,
2457
+ tasks: runningTasks
2458
+ }
2459
+ },
2460
+ totals: {
2461
+ totalTasks: pendingTasks.length + readyTasks.length + runningTasks.length,
2462
+ pendingTasks: pendingTasks.length,
2463
+ readyTasks: readyTasks.length,
2464
+ runningTasks: runningTasks.length
2465
+ },
2466
+ coalescing: coalescingInfo,
2467
+ delays: {
2468
+ activeDelays: this.nextAvailableTime > now ? 1 : 0,
2469
+ delayDetails:
2470
+ this.nextAvailableTime > now
2471
+ ? [
2472
+ {
2473
+ priority: this.lastCompletedPriority,
2474
+ expiresAt: this.nextAvailableTime,
2475
+ expiresIn: this.nextAvailableTime - now
2476
+ }
2477
+ ]
2478
+ : []
2479
+ }
2480
+ };
2481
+ }
2482
+
2483
+ /**
2484
+ * Get information about active timers and scheduler state.
2485
+ * @returns {Object} Timer and scheduler information
2486
+ */
2487
+ inspectTimers() {
2488
+ const now = this.now();
2489
+
2490
+ return {
2491
+ schedulerInterval: {
2492
+ id: this.schedulerInterval,
2493
+ active: this.schedulerInterval !== null,
2494
+ type: "interval"
2495
+ },
2496
+ schedulerTimeout: {
2497
+ id: this.schedulerTimeout,
2498
+ active: this.schedulerTimeout !== null,
2499
+ type: "timeout"
2500
+ },
2501
+ nextScheduledRun: this.nextScheduledRun,
2502
+ nextRunIn: this.nextScheduledRun ? this.nextScheduledRun - now : null,
2503
+ smartScheduling: this.options.smartScheduling,
2504
+ tickInterval: this.options.tick
2505
+ };
2506
+ }
2507
+
2508
+ /**
2509
+ * Get a summary of all queued tasks by status.
2510
+ * @returns {Object} Task summary by status
2511
+ */
2512
+ inspectTasks() {
2513
+ const now = this.now();
2514
+
2515
+ const summary = {
2516
+ pending: [],
2517
+ ready: [],
2518
+ running: [],
2519
+ byPriority: {},
2520
+ byCoalescingKey: {},
2521
+ total: 0
2522
+ };
2523
+
2524
+ // Process pending tasks
2525
+ [...this.pendingHeap.heap].forEach((task) => {
2526
+ const taskInfo = {
2527
+ id: task.id,
2528
+ priority: task.priority,
2529
+ readyAt: task.readyAt,
2530
+ readyIn: task.readyAt - now,
2531
+ coalescingKey: task.coalescingKey,
2532
+ metadata: task.metadata
2533
+ };
2534
+ summary.pending.push(taskInfo);
2535
+ summary.total++;
2536
+
2537
+ // Group by priority
2538
+ if (!summary.byPriority[task.priority]) {
2539
+ summary.byPriority[task.priority] = { pending: 0, ready: 0, running: 0 };
2540
+ }
2541
+ summary.byPriority[task.priority].pending++;
2542
+
2543
+ // Group by coalescing key
2544
+ if (task.coalescingKey) {
2545
+ if (!summary.byCoalescingKey[task.coalescingKey]) {
2546
+ summary.byCoalescingKey[task.coalescingKey] = { pending: 0, ready: 0, running: 0 };
2547
+ }
2548
+ summary.byCoalescingKey[task.coalescingKey].pending++;
2549
+ }
2550
+ });
2551
+
2552
+ // Process ready tasks
2553
+ [...this.readyHeap.heap].forEach((task) => {
2554
+ const taskInfo = {
2555
+ id: task.id,
2556
+ priority: task.priority,
2557
+ coalescingKey: task.coalescingKey,
2558
+ metadata: task.metadata
2559
+ };
2560
+ summary.ready.push(taskInfo);
2561
+ summary.total++;
2562
+
2563
+ // Group by priority
2564
+ if (!summary.byPriority[task.priority]) {
2565
+ summary.byPriority[task.priority] = { pending: 0, ready: 0, running: 0 };
2566
+ }
2567
+ summary.byPriority[task.priority].ready++;
2568
+
2569
+ // Group by coalescing key
2570
+ if (task.coalescingKey) {
2571
+ if (!summary.byCoalescingKey[task.coalescingKey]) {
2572
+ summary.byCoalescingKey[task.coalescingKey] = { pending: 0, ready: 0, running: 0 };
2573
+ }
2574
+ summary.byCoalescingKey[task.coalescingKey].ready++;
2575
+ }
2576
+ });
2577
+
2578
+ // Process running tasks
2579
+ Array.from(this.running).forEach((task) => {
2580
+ const taskInfo = {
2581
+ id: task.id,
2582
+ priority: task.priority,
2583
+ coalescingKey: task.coalescingKey,
2584
+ metadata: task.metadata,
2585
+ startedAt: task.startedAt,
2586
+ runningFor: now - task.startedAt
2587
+ };
2588
+ summary.running.push(taskInfo);
2589
+ summary.total++;
2590
+
2591
+ // Group by priority
2592
+ if (!summary.byPriority[task.priority]) {
2593
+ summary.byPriority[task.priority] = { pending: 0, ready: 0, running: 0 };
2594
+ }
2595
+ summary.byPriority[task.priority].running++;
2596
+
2597
+ // Group by coalescing key
2598
+ if (task.coalescingKey) {
2599
+ if (!summary.byCoalescingKey[task.coalescingKey]) {
2600
+ summary.byCoalescingKey[task.coalescingKey] = { pending: 0, ready: 0, running: 0 };
2601
+ }
2602
+ summary.byCoalescingKey[task.coalescingKey].running++;
2603
+ }
2604
+ });
2605
+
2606
+ return summary;
2607
+ }
2608
+
2609
+ /**
2610
+ * Get detailed information about the scheduler state and timing.
2611
+ * @returns {Object} Scheduler state information
2612
+ */
2613
+ inspectScheduler() {
2614
+ const now = this.now();
2615
+
2616
+ // Calculate next run time for different scenarios
2617
+ let nextTaskTime = Infinity;
2618
+ let nextTaskInfo = null;
2619
+
2620
+ // Check pending tasks
2621
+ if (this.pendingHeap.size() > 0) {
2622
+ const nextPending = this.pendingHeap.peek();
2623
+ if (nextPending && nextPending.readyAt < nextTaskTime) {
2624
+ nextTaskTime = nextPending.readyAt;
2625
+ nextTaskInfo = {
2626
+ id: nextPending.id,
2627
+ priority: nextPending.priority,
2628
+ readyAt: nextPending.readyAt,
2629
+ source: "pending"
2630
+ };
2631
+ }
2632
+ }
2633
+
2634
+ // Check ready tasks
2635
+ if (this.readyHeap.size() > 0) {
2636
+ const nextReady = this.readyHeap.peek();
2637
+ if (nextReady) {
2638
+ nextTaskTime = now;
2639
+ nextTaskInfo = {
2640
+ id: nextReady.id,
2641
+ priority: nextReady.priority,
2642
+ source: "ready"
2643
+ };
2644
+ }
2645
+ }
2646
+
2647
+ // Check active delays
2648
+ let delayInfo = null;
2649
+ if (this.nextAvailableTime > now) {
2650
+ delayInfo = {
2651
+ priority: this.lastCompletedPriority,
2652
+ expiresAt: this.nextAvailableTime
2653
+ };
2654
+ }
2655
+
2656
+ return {
2657
+ timestamp: now,
2658
+ isActive: this.isActive,
2659
+ smartScheduling: this.options.smartScheduling,
2660
+ concurrency: this.options.concurrency,
2661
+ currentConcurrency: this.running.size,
2662
+ availableSlots: this.options.concurrency - this.running.size,
2663
+ timers: {
2664
+ schedulerInterval: this.schedulerInterval,
2665
+ schedulerTimeout: this.schedulerTimeout,
2666
+ nextScheduledRun: this.nextScheduledRun,
2667
+ nextRunIn: this.nextScheduledRun ? this.nextScheduledRun - now : null
2668
+ },
2669
+ nextTask: nextTaskInfo
2670
+ ? {
2671
+ ...nextTaskInfo,
2672
+ readyIn: nextTaskTime - now,
2673
+ canRunNow: nextTaskTime <= now && this.running.size < this.options.concurrency
2674
+ }
2675
+ : null,
2676
+ delays: {
2677
+ hasActiveDelays: this.nextAvailableTime > now,
2678
+ count: this.nextAvailableTime > now ? 1 : 0,
2679
+ nextExpiry: delayInfo
2680
+ ? {
2681
+ ...delayInfo,
2682
+ expiresIn: delayInfo.expiresAt - now
2683
+ }
2684
+ : null
2685
+ },
2686
+ queueCounts: {
2687
+ pending: this.pendingHeap.size(),
2688
+ ready: this.readyHeap.size(),
2689
+ running: this.running.size,
2690
+ total: this.pendingHeap.size() + this.readyHeap.size() + this.running.size
2691
+ }
2692
+ };
2693
+ }
2694
+
2695
+ /**
2696
+ * Log comprehensive queue state to console for debugging.
2697
+ * @param {boolean} [detailed=false] - Whether to include detailed task information
2698
+ */
2699
+ debugLog(detailed = false) {
2700
+ const inspection = this.inspect();
2701
+
2702
+ console.log("\n=== HoldMyTask Debug Information ===");
2703
+ console.log(`Timestamp: ${new Date(inspection.timestamp).toISOString()}`);
2704
+ console.log(`Status: ${inspection.scheduler.isActive ? "ACTIVE" : "PAUSED"}`);
2705
+ console.log(`Smart Scheduling: ${inspection.scheduler.smartScheduling ? "ON" : "OFF"}`);
2706
+ console.log(`Concurrency: ${inspection.scheduler.currentConcurrency}/${inspection.scheduler.concurrency}`);
2707
+
2708
+ console.log("\n--- Queue State ---");
2709
+ console.log(`Total Tasks: ${inspection.totals.totalTasks}`);
2710
+ console.log(` Pending: ${inspection.totals.pendingTasks}`);
2711
+ console.log(` Ready: ${inspection.totals.readyTasks}`);
2712
+ console.log(` Running: ${inspection.totals.runningTasks}`);
2713
+
2714
+ console.log("\n--- Timer State ---");
2715
+ console.log(`Interval: ${inspection.timers.schedulerInterval.active ? `Active (${inspection.timers.schedulerInterval.id})` : "None"}`);
2716
+ console.log(`Timeout: ${inspection.timers.schedulerTimeout.active ? `Active (${inspection.timers.schedulerTimeout.id})` : "None"}`);
2717
+ if (inspection.timers.nextRunIn !== null) {
2718
+ console.log(`Next Run: ${inspection.timers.nextRunIn}ms`);
2719
+ }
2720
+
2721
+ if (inspection.delays.activeDelays > 0) {
2722
+ console.log("\n--- Active Delays ---");
2723
+ inspection.delays.delayDetails.forEach((delay) => {
2724
+ console.log(` Priority ${delay.priority}: expires in ${delay.expiresIn}ms`);
2725
+ });
2726
+ }
2727
+
2728
+ if (Object.keys(inspection.coalescing).length > 0) {
2729
+ console.log("\n--- Coalescing Groups ---");
2730
+ Object.entries(inspection.coalescing).forEach(([key, info]) => {
2731
+ console.log(` ${key}: ${info.groupCount} groups, ${info.totalTasks} tasks`);
2732
+ });
2733
+ }
2734
+
2735
+ if (detailed) {
2736
+ console.log("\n--- Detailed Task Information ---");
2737
+ if (inspection.queues.pending.count > 0) {
2738
+ console.log("\nPending Tasks:");
2739
+ inspection.queues.pending.tasks.forEach((task) => {
2740
+ console.log(` ${task.id}: priority ${task.priority}, ready in ${task.readyIn}ms`);
2741
+ });
2742
+ }
2743
+
2744
+ if (inspection.queues.ready.count > 0) {
2745
+ console.log("\nReady Tasks:");
2746
+ inspection.queues.ready.tasks.forEach((task) => {
2747
+ console.log(` ${task.id}: priority ${task.priority}`);
2748
+ });
2749
+ }
2750
+
2751
+ if (inspection.queues.running.count > 0) {
2752
+ console.log("\nRunning Tasks:");
2753
+ inspection.queues.running.tasks.forEach((task) => {
2754
+ console.log(` ${task.id}: priority ${task.priority}, running for ${task.runningFor}ms`);
2755
+ });
2756
+ }
2757
+ }
2758
+
2759
+ console.log("=====================================\n");
2760
+ }
2365
2761
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/holdmytask",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "A tiny task queue that waits until your task is ready",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.mjs",
@@ -687,6 +687,31 @@ export class HoldMyTask extends EventEmitter<[never]> {
687
687
  * @returns {boolean} True if task exists, false otherwise
688
688
  */
689
689
  hasTask(id: string | number): boolean;
690
+ /**
691
+ * Get detailed information about the current queue state for debugging.
692
+ * @returns {Object} Comprehensive queue state information
693
+ */
694
+ inspect(): any;
695
+ /**
696
+ * Get information about active timers and scheduler state.
697
+ * @returns {Object} Timer and scheduler information
698
+ */
699
+ inspectTimers(): any;
700
+ /**
701
+ * Get a summary of all queued tasks by status.
702
+ * @returns {Object} Task summary by status
703
+ */
704
+ inspectTasks(): any;
705
+ /**
706
+ * Get detailed information about the scheduler state and timing.
707
+ * @returns {Object} Scheduler state information
708
+ */
709
+ inspectScheduler(): any;
710
+ /**
711
+ * Log comprehensive queue state to console for debugging.
712
+ * @param {boolean} [detailed=false] - Whether to include detailed task information
713
+ */
714
+ debugLog(detailed?: boolean): void;
690
715
  }
691
716
  import { EventEmitter } from "events";
692
717
  import { MinHeap } from "./utils.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"hold-my-task.d.mts","sourceRoot":"","sources":["../../dist/hold-my-task.mjs"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6DG;IAEH;;;;;;;;OAQG;IACH,yCAwCC;IAwND;;;;;;;;;OASG;IACH,uBAGC;IAnOD,0BAaC;I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BAAkB,GAAnC,OAAO;KACf,GAAU,IAAI,CAyDhB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,mCAfW,MAAM,0BAmChB;IAED;;;;;;;;;;OAUG;IACH,mCAMC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,4BApBW,MAAM,UAEd;QAAwB,SAAS,GAAzB,MAAM;QACU,UAAU,GAA1B,MAAM;QACU,KAAK,GAArB,MAAM;QACU,KAAK,GAArB,MAAM;KACd,GAAU,IAAI,CA2ChB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,4BAfW,MAAM,0BA6BhB;IAED;;;;;;;;;;OAUG;IACH,iCAMC;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;;;;;OAMG;IACH,4CAJW,cAAe,kBAEb,eAAQ,UAAU,CAI9B;IAED;;;;;;OAMG;IACH,uCAJW,cAAe,kBAEb,eAAQ,UAAU,CAI9B;IAED;;;;OAIG;IACH,QAHW,MAAM,GAAC,MAAM,GACX,MAAO,IAAI,CAIvB;IAED;;;;OAIG;IACH,QAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAInB;IAED;;;;OAIG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,MAAO,IAAI,CAIvB;IAED;;;;OAIG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAInB;CACD;6BA/yE4B,QAAQ;wBACb,aAAa"}
1
+ {"version":3,"file":"hold-my-task.d.mts","sourceRoot":"","sources":["../../dist/hold-my-task.mjs"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6DG;IAEH;;;;;;;;OAQG;IACH,yCAwCC;IAwND;;;;;;;;;OASG;IACH,uBAGC;IAnOD,0BAaC;IAED;;;;OAIG;IACH,wBAGC;IAFA,mBAAqB;IAItB;;;;;OAKG;IACH,yBAUC;IAED;;;;OAIG;IACH,0BAoKC;IA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