hammerwork 1.15.5

A high-performance, database-driven job queue for Rust with PostgreSQL and MySQL support, featuring job prioritization, cron scheduling, event streaming (Kafka/Kinesis/PubSub), webhooks, rate limiting, Prometheus metrics, and comprehensive monitoring
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
//! # Job Result Storage Example
//!
//! This example demonstrates how to use Hammerwork's job result storage functionality
//! to store and retrieve data from completed jobs.
//!
//! ## Features Demonstrated
//!
//! - Creating jobs with result storage enabled
//! - Using enhanced job handlers that return result data
//! - Configuring TTL (time-to-live) for results
//! - Automatic result storage by workers
//! - Manual result retrieval and cleanup
//! - Different result storage configurations
//!
//! ## Usage
//!
//! ```bash
//! # With PostgreSQL
//! DATABASE_URL=postgresql://localhost/hammerwork cargo run --example result_storage_example --features postgres
//!
//! # With MySQL  
//! DATABASE_URL=mysql://localhost/hammerwork cargo run --example result_storage_example --features mysql
//! ```

use hammerwork::{
    Job, JobQueue, Worker, WorkerPool,
    job::ResultStorage,
    queue::DatabaseQueue,
    worker::{JobHandler, JobHandlerWithResult, JobResult},
};
use serde_json::json;
use std::{sync::Arc, time::Duration};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize logging
    tracing_subscriber::fmt::init();

    // Connect to database
    let database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| {
        #[cfg(all(feature = "postgres", not(feature = "mysql")))]
        return "postgresql://localhost/hammerwork".to_string();
        #[cfg(all(feature = "mysql", not(feature = "postgres")))]
        return "mysql://localhost/hammerwork".to_string();
        #[cfg(all(feature = "postgres", feature = "mysql"))]
        return "postgresql://localhost/hammerwork".to_string(); // Default to postgres when both enabled
        #[cfg(not(any(feature = "postgres", feature = "mysql")))]
        panic!("No database feature enabled. Use --features postgres or --features mysql");
    });

    println!("๐Ÿ”— Connecting to database: {}", database_url);

    #[cfg(all(feature = "postgres", not(feature = "mysql")))]
    let pool = sqlx::PgPool::connect(&database_url).await?;
    #[cfg(all(feature = "mysql", not(feature = "postgres")))]
    let pool = sqlx::MySqlPool::connect(&database_url).await?;
    #[cfg(all(feature = "postgres", feature = "mysql"))]
    let pool = sqlx::PgPool::connect(&database_url).await?; // Default to postgres when both enabled

    let queue = Arc::new(JobQueue::new(pool));

    // Initialize database tables
    // Note: Run `cargo hammerwork migrate` to create the necessary database tables
    println!("๐Ÿ“‹ Database tables should be initialized using 'cargo hammerwork migrate'");

    // Demonstrate different aspects of result storage
    #[cfg(any(
        all(feature = "postgres", not(feature = "mysql")),
        all(feature = "postgres", feature = "mysql")
    ))]
    {
        demonstrate_basic_result_storage_postgres(&queue).await?;
        demonstrate_enhanced_workers_postgres(&queue).await?;
        demonstrate_result_expiration_postgres(&queue).await?;
        demonstrate_legacy_compatibility_postgres(&queue).await?;
    }

    #[cfg(all(feature = "mysql", not(feature = "postgres")))]
    {
        demonstrate_basic_result_storage_mysql(&queue).await?;
        demonstrate_enhanced_workers_mysql(&queue).await?;
        demonstrate_result_expiration_mysql(&queue).await?;
        demonstrate_legacy_compatibility_mysql(&queue).await?;
    }

    println!("โœ… Example completed successfully!");
    Ok(())
}

#[cfg(feature = "postgres")]
async fn demonstrate_basic_result_storage_postgres(
    queue: &Arc<JobQueue<sqlx::Postgres>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐ŸŽฏ === Basic Result Storage ===");

    // Create a job with result storage enabled
    let job = Job::new(
        "data_processing".to_string(),
        json!({
            "dataset": "customer_data_2024",
            "operation": "analytics"
        }),
    )
    .with_result_storage(ResultStorage::Database)
    .with_result_ttl(Duration::from_secs(3600)); // 1 hour TTL

    println!("๐Ÿ“ Created job with result storage enabled");
    let job_id = queue.enqueue(job).await?;
    println!("   Job ID: {}", job_id);

    // Simulate processing and store result manually
    let processing_result = json!({
        "total_records": 150_000,
        "processed_records": 149_890,
        "errors": 110,
        "processing_time_ms": 45_230,
        "output_files": [
            "/data/output/summary.json",
            "/data/output/detailed_report.csv"
        ],
        "statistics": {
            "avg_processing_time_per_record_ms": 0.301,
            "memory_usage_mb": 2_048,
            "cpu_usage_percent": 85.2
        }
    });

    println!("๐Ÿ’พ Storing job result...");
    queue
        .store_job_result(job_id, processing_result.clone(), None)
        .await?;

    // Retrieve the result
    println!("๐Ÿ” Retrieving stored result...");
    if let Some(stored_result) = queue.get_job_result(job_id).await? {
        println!("   โœ… Result retrieved successfully");
        println!("   ๐Ÿ“Š Processed {} records", stored_result["total_records"]);
        println!(
            "   โฑ๏ธ  Processing time: {}ms",
            stored_result["processing_time_ms"]
        );
        println!("   ๐Ÿ“ Output files: {:?}", stored_result["output_files"]);
    } else {
        println!("   โŒ No result found");
    }

    // Clean up
    queue.delete_job_result(job_id).await?;
    println!("๐Ÿ—‘๏ธ  Result deleted");

    Ok(())
}

#[cfg(feature = "postgres")]
async fn demonstrate_enhanced_workers_postgres(
    queue: &Arc<JobQueue<sqlx::Postgres>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿค– === Enhanced Workers with Result Storage ===");

    // Create an enhanced job handler that returns result data
    let handler: JobHandlerWithResult = Arc::new(|job| {
        Box::pin(async move {
            let start_time = std::time::Instant::now();

            // Simulate different types of processing based on job payload
            let task_type = job.payload["task_type"].as_str().unwrap_or("default");
            let processing_duration = match task_type {
                "quick" => Duration::from_millis(100),
                "medium" => Duration::from_millis(500),
                "heavy" => Duration::from_millis(1000),
                _ => Duration::from_millis(300),
            };

            println!(
                "   ๐Ÿ”„ Processing {} task (estimated {}ms)...",
                task_type,
                processing_duration.as_millis()
            );

            // Simulate processing
            tokio::time::sleep(processing_duration).await;

            let actual_duration = start_time.elapsed();

            // Generate realistic result data
            let result_data = match task_type {
                "quick" => json!({
                    "task_type": task_type,
                    "processing_time_ms": actual_duration.as_millis(),
                    "cache_hits": 95,
                    "cache_misses": 5,
                    "status": "completed"
                }),
                "medium" => json!({
                    "task_type": task_type,
                    "processing_time_ms": actual_duration.as_millis(),
                    "records_processed": 1_000,
                    "transformations_applied": 15,
                    "validation_passed": true,
                    "output_size_bytes": 256_000,
                    "status": "completed"
                }),
                "heavy" => json!({
                    "task_type": task_type,
                    "processing_time_ms": actual_duration.as_millis(),
                    "dataset_size_gb": 2.5,
                    "models_trained": 3,
                    "accuracy_score": 0.94,
                    "feature_importance": {
                        "price": 0.45,
                        "location": 0.32,
                        "size": 0.23
                    },
                    "status": "completed"
                }),
                _ => json!({
                    "task_type": task_type,
                    "processing_time_ms": actual_duration.as_millis(),
                    "status": "completed"
                }),
            };

            println!("   โœ… Task completed in {}ms", actual_duration.as_millis());

            Ok(JobResult::with_data(result_data))
        })
    });

    // Create worker with enhanced handler
    let worker =
        Worker::new_with_result_handler(queue.clone(), "enhanced_processing".to_string(), handler)
            .with_poll_interval(Duration::from_millis(100));

    // Create different types of jobs
    let job_types = ["quick", "medium", "heavy"];
    let mut job_ids = Vec::new();

    for task_type in &job_types {
        let job = Job::new(
            "enhanced_processing".to_string(),
            json!({
                "task_type": task_type,
                "priority": "high"
            }),
        )
        .with_result_storage(ResultStorage::Database)
        .with_result_ttl(Duration::from_secs(7200)); // 2 hours TTL

        let job_id = queue.enqueue(job).await?;
        job_ids.push(job_id);
        println!("๐Ÿ“ Enqueued {} task with ID: {}", task_type, job_id);
    }

    // Start worker pool to process jobs
    println!("๐Ÿš€ Starting worker to process jobs...");
    let mut worker_pool = WorkerPool::new();
    worker_pool.add_worker(worker);

    // Run worker pool for a limited time
    let worker_handle = tokio::spawn(async move { worker_pool.start().await });

    // Wait for jobs to be processed
    tokio::time::sleep(Duration::from_secs(3)).await;

    // Check results for each job
    println!("๐Ÿ” Checking stored results...");
    for (i, &job_id) in job_ids.iter().enumerate() {
        if let Some(result) = queue.get_job_result(job_id).await? {
            println!("   ๐Ÿ“Š {} task result:", job_types[i]);
            println!(
                "      - Processing time: {}ms",
                result["processing_time_ms"]
            );
            println!("      - Status: {}", result["status"]);

            // Show specific metrics based on task type
            match job_types[i] {
                "quick" => {
                    println!("      - Cache hits: {}", result["cache_hits"]);
                }
                "medium" => {
                    println!("      - Records processed: {}", result["records_processed"]);
                    println!("      - Output size: {} bytes", result["output_size_bytes"]);
                }
                "heavy" => {
                    println!("      - Dataset size: {} GB", result["dataset_size_gb"]);
                    println!("      - Models trained: {}", result["models_trained"]);
                    println!("      - Accuracy: {}", result["accuracy_score"]);
                }
                _ => {}
            }
        } else {
            println!("   โŒ No result found for {} task", job_types[i]);
        }
    }

    // Stop worker
    worker_handle.abort();
    println!("๐Ÿ›‘ Worker stopped");

    Ok(())
}

#[cfg(feature = "postgres")]
async fn demonstrate_result_expiration_postgres(
    queue: &Arc<JobQueue<sqlx::Postgres>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\nโฐ === Result Expiration and Cleanup ===");

    // Create jobs with different expiration times
    let job1 = Job::new(
        "temp_processing".to_string(),
        json!({"task": "short_lived"}),
    );
    let job2 = Job::new("temp_processing".to_string(), json!({"task": "long_lived"}));

    let job_id1 = queue.enqueue(job1).await?;
    let job_id2 = queue.enqueue(job2).await?;

    // Store results with different expiration times
    let short_lived_result = json!({"data": "expires_soon", "created_at": chrono::Utc::now()});
    let long_lived_result = json!({"data": "expires_later", "created_at": chrono::Utc::now()});

    // First result expires in 2 seconds
    let expires_soon = chrono::Utc::now() + chrono::Duration::seconds(2);
    // Second result expires in 1 hour
    let expires_later = chrono::Utc::now() + chrono::Duration::hours(1);

    println!("๐Ÿ’พ Storing results with different expiration times...");
    queue
        .store_job_result(job_id1, short_lived_result, Some(expires_soon))
        .await?;
    queue
        .store_job_result(job_id2, long_lived_result, Some(expires_later))
        .await?;

    // Check both results are initially available
    println!("๐Ÿ” Checking initial availability...");
    assert!(queue.get_job_result(job_id1).await?.is_some());
    assert!(queue.get_job_result(job_id2).await?.is_some());
    println!("   โœ… Both results available");

    // Wait for the first result to expire
    println!("โณ Waiting for first result to expire...");
    tokio::time::sleep(Duration::from_secs(3)).await;

    // Check results after expiration
    println!("๐Ÿ” Checking after expiration...");
    let result1 = queue.get_job_result(job_id1).await?;
    let result2 = queue.get_job_result(job_id2).await?;

    if result1.is_none() {
        println!("   โœ… Short-lived result correctly expired");
    } else {
        println!("   โŒ Short-lived result should have expired");
    }

    if result2.is_some() {
        println!("   โœ… Long-lived result still available");
    } else {
        println!("   โŒ Long-lived result should still be available");
    }

    // Demonstrate cleanup of expired results
    println!("๐Ÿงน Running cleanup of expired results...");
    let cleaned_count = queue.cleanup_expired_results().await?;
    println!("   ๐Ÿ—‘๏ธ  Cleaned up {} expired results", cleaned_count);

    Ok(())
}

#[cfg(feature = "postgres")]
async fn demonstrate_legacy_compatibility_postgres(
    queue: &Arc<JobQueue<sqlx::Postgres>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿ”„ === Legacy Handler Compatibility ===");

    // Create a traditional job handler (returns ())
    let legacy_handler: JobHandler = Arc::new(|_job| {
        Box::pin(async move {
            println!("   ๐Ÿ”ง Processing job with legacy handler...");

            // Simulate work
            let work_duration = Duration::from_millis(200);
            tokio::time::sleep(work_duration).await;

            // Legacy handlers just return Ok(()) - no result data
            println!("   โœ… Legacy job completed successfully");
            Ok(())
        })
    });

    // Create worker with legacy handler
    let legacy_worker = Worker::new(queue.clone(), "legacy_queue".to_string(), legacy_handler)
        .with_poll_interval(Duration::from_millis(100));

    // Create jobs - some with result storage enabled, some without
    let job1 = Job::new("legacy_queue".to_string(), json!({"task": "no_storage"}))
        .with_result_storage(ResultStorage::None);

    let job2 = Job::new(
        "legacy_queue".to_string(),
        json!({"task": "storage_enabled"}),
    )
    .with_result_storage(ResultStorage::Database);

    let job_id1 = queue.enqueue(job1).await?;
    let job_id2 = queue.enqueue(job2).await?;

    println!("๐Ÿ“ Created jobs with legacy worker:");
    println!("   - Job 1: Result storage disabled");
    println!("   - Job 2: Result storage enabled (but handler returns no data)");

    // Process jobs
    let mut worker_pool = WorkerPool::new();
    worker_pool.add_worker(legacy_worker);

    let worker_handle = tokio::spawn(async move { worker_pool.start().await });

    tokio::time::sleep(Duration::from_secs(1)).await;

    // Check results
    println!("๐Ÿ” Checking results from legacy handler:");

    let result1 = queue.get_job_result(job_id1).await?;
    let result2 = queue.get_job_result(job_id2).await?;

    if result1.is_none() && result2.is_none() {
        println!("   โœ… No results stored (expected for legacy handlers)");
        println!("   ๐Ÿ’ก Legacy handlers work normally, just without result data");
    } else {
        println!("   โš ๏ธ  Unexpected results found");
    }

    worker_handle.abort();

    Ok(())
}

// MySQL versions of the demonstration functions
#[cfg(feature = "mysql")]
#[allow(dead_code)]
async fn demonstrate_basic_result_storage_mysql(
    queue: &Arc<JobQueue<sqlx::MySql>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐ŸŽฏ === Basic Result Storage (MySQL) ===");

    // Create a job with result storage enabled
    let job = Job::new(
        "data_processing".to_string(),
        json!({
            "dataset": "customer_data_2024",
            "operation": "analytics"
        }),
    )
    .with_result_storage(ResultStorage::Database)
    .with_result_ttl(Duration::from_secs(3600)); // 1 hour TTL

    println!("๐Ÿ“ Created job with result storage enabled");
    let job_id = queue.enqueue(job).await?;
    println!("   Job ID: {}", job_id);

    // Simulate processing and store result manually
    let processing_result = json!({
        "total_records": 150_000,
        "processed_records": 149_890,
        "errors": 110,
        "processing_time_ms": 45_230,
        "output_files": [
            "/data/output/summary.json",
            "/data/output/detailed_report.csv"
        ],
        "database": "mysql"
    });

    println!("๐Ÿ’พ Storing job result...");
    queue
        .store_job_result(job_id, processing_result.clone(), None)
        .await?;

    // Retrieve the result
    println!("๐Ÿ” Retrieving stored result...");
    if let Some(stored_result) = queue.get_job_result(job_id).await? {
        println!("   โœ… Result retrieved successfully from MySQL");
        println!("   ๐Ÿ“Š Processed {} records", stored_result["total_records"]);
        println!(
            "   โฑ๏ธ  Processing time: {}ms",
            stored_result["processing_time_ms"]
        );
    } else {
        println!("   โŒ No result found");
    }

    // Clean up
    queue.delete_job_result(job_id).await?;
    println!("๐Ÿ—‘๏ธ  Result deleted");

    Ok(())
}

#[cfg(feature = "mysql")]
#[allow(dead_code)]
async fn demonstrate_enhanced_workers_mysql(
    queue: &Arc<JobQueue<sqlx::MySql>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿค– === Enhanced Workers with Result Storage (MySQL) ===");

    // Create an enhanced job handler
    let handler: JobHandlerWithResult = Arc::new(|job| {
        Box::pin(async move {
            let task_type = job.payload["task_type"].as_str().unwrap_or("default");

            println!("   ๐Ÿ”„ Processing {} task with MySQL backend...", task_type);

            // Simulate processing
            tokio::time::sleep(Duration::from_millis(300)).await;

            let result_data = json!({
                "task_type": task_type,
                "database": "mysql",
                "processing_time_ms": 300,
                "status": "completed"
            });

            println!("   โœ… Task completed");
            Ok(JobResult::with_data(result_data))
        })
    });

    // Create worker
    let worker =
        Worker::new_with_result_handler(queue.clone(), "mysql_processing".to_string(), handler);

    // Create a job
    let job = Job::new(
        "mysql_processing".to_string(),
        json!({"task_type": "mysql_test"}),
    )
    .with_result_storage(ResultStorage::Database);

    let job_id = queue.enqueue(job).await?;
    println!("๐Ÿ“ Enqueued MySQL job with ID: {}", job_id);

    // Process the job
    let mut worker_pool = WorkerPool::new();
    worker_pool.add_worker(worker);

    let worker_handle = tokio::spawn(async move { worker_pool.start().await });

    tokio::time::sleep(Duration::from_secs(1)).await;

    // Check result
    if let Some(result) = queue.get_job_result(job_id).await? {
        println!("   ๐Ÿ“Š MySQL result:");
        println!("      - Database: {}", result["database"]);
        println!("      - Status: {}", result["status"]);
    }

    worker_handle.abort();
    Ok(())
}

#[cfg(feature = "mysql")]
#[allow(dead_code)]
async fn demonstrate_result_expiration_mysql(
    queue: &Arc<JobQueue<sqlx::MySql>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\nโฐ === Result Expiration and Cleanup (MySQL) ===");

    let job = Job::new(
        "temp_processing".to_string(),
        json!({"task": "mysql_expiration"}),
    );
    let job_id = queue.enqueue(job).await?;

    let result_data = json!({"data": "expires_soon", "database": "mysql"});
    let expires_soon = chrono::Utc::now() + chrono::Duration::seconds(2);

    println!("๐Ÿ’พ Storing MySQL result with 2-second TTL...");
    queue
        .store_job_result(job_id, result_data, Some(expires_soon))
        .await?;

    println!("๐Ÿ” Result available initially");
    assert!(queue.get_job_result(job_id).await?.is_some());

    println!("โณ Waiting for expiration...");
    tokio::time::sleep(Duration::from_secs(3)).await;

    let result_after_expiration = queue.get_job_result(job_id).await?;
    if result_after_expiration.is_none() {
        println!("   โœ… MySQL result correctly expired");
    }

    let cleaned_count = queue.cleanup_expired_results().await?;
    println!("๐Ÿงน Cleaned up {} expired MySQL results", cleaned_count);

    Ok(())
}

#[cfg(feature = "mysql")]
#[allow(dead_code)]
async fn demonstrate_legacy_compatibility_mysql(
    queue: &Arc<JobQueue<sqlx::MySql>>,
) -> Result<(), Box<dyn std::error::Error>> {
    println!("\n๐Ÿ”„ === Legacy Handler Compatibility (MySQL) ===");

    let legacy_handler: JobHandler = Arc::new(|_job| {
        Box::pin(async move {
            println!("   ๐Ÿ”ง Processing job with legacy handler on MySQL...");
            tokio::time::sleep(Duration::from_millis(200)).await;
            println!("   โœ… Legacy MySQL job completed");
            Ok(())
        })
    });

    let legacy_worker = Worker::new(queue.clone(), "mysql_legacy".to_string(), legacy_handler);

    let job = Job::new("mysql_legacy".to_string(), json!({"task": "legacy_mysql"}))
        .with_result_storage(ResultStorage::Database);

    let job_id = queue.enqueue(job).await?;

    let mut worker_pool = WorkerPool::new();
    worker_pool.add_worker(legacy_worker);

    let worker_handle = tokio::spawn(async move { worker_pool.start().await });

    tokio::time::sleep(Duration::from_secs(1)).await;

    let result = queue.get_job_result(job_id).await?;
    if result.is_none() {
        println!("   โœ… No result stored for MySQL legacy handler (expected)");
    }

    worker_handle.abort();
    Ok(())
}