-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathmod.rs
766 lines (711 loc) · 24.8 KB
/
mod.rs
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
sync::Arc,
};
use async_trait::async_trait;
#[cfg(feature = "cli")]
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use serde_variant::to_variant_name;
#[cfg(feature = "bg_pg")]
pub mod pg;
#[cfg(feature = "bg_redis")]
pub mod skq;
#[cfg(feature = "bg_sqlt")]
pub mod sqlt;
use crate::{
app::AppContext,
config::{
self, Config, PostgresQueueConfig, QueueConfig, RedisQueueConfig, SqliteQueueConfig,
WorkerMode,
},
Error, Result,
};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "cli", derive(ValueEnum))]
pub enum JobStatus {
#[serde(rename = "queued")]
Queued,
#[serde(rename = "processing")]
Processing,
#[serde(rename = "completed")]
Completed,
#[serde(rename = "failed")]
Failed,
#[serde(rename = "cancelled")]
Cancelled,
}
impl std::str::FromStr for JobStatus {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"queued" => Ok(Self::Queued),
"processing" => Ok(Self::Processing),
"completed" => Ok(Self::Completed),
"failed" => Ok(Self::Failed),
"cancelled" => Ok(Self::Cancelled),
_ => Err(format!("Invalid status: {s}")),
}
}
}
impl std::fmt::Display for JobStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
to_variant_name(self).expect("only enum supported").fmt(f)
}
}
// Queue struct now holds both a QueueProvider and QueueRegistrar
pub enum Queue {
#[cfg(feature = "bg_redis")]
Redis(
bb8::Pool<sidekiq::RedisConnectionManager>,
Arc<tokio::sync::Mutex<sidekiq::Processor>>,
tokio_util::sync::CancellationToken,
),
#[cfg(feature = "bg_pg")]
Postgres(
pg::PgPool,
std::sync::Arc<tokio::sync::Mutex<pg::JobRegistry>>,
pg::RunOpts,
),
#[cfg(feature = "bg_sqlt")]
Sqlite(
sqlt::SqlitePool,
std::sync::Arc<tokio::sync::Mutex<sqlt::JobRegistry>>,
sqlt::RunOpts,
),
None,
}
impl Queue {
/// Add a job to the queue
///
/// # Errors
///
/// This function will return an error if fails
#[allow(unused_variables)]
pub async fn enqueue<A: Serialize + Send + Sync>(
&self,
class: String,
queue: Option<String>,
args: A,
) -> Result<()> {
tracing::debug!(worker = class, "job enqueue");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(pool, _, _) => {
skq::enqueue(pool, class, queue, args).await?;
}
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
pg::enqueue(
pool,
&class,
serde_json::to_value(args)?,
chrono::Utc::now(),
None,
)
.await
.map_err(Box::from)?;
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
sqlt::enqueue(
pool,
&class,
serde_json::to_value(args)?,
chrono::Utc::now(),
None,
)
.await
.map_err(Box::from)?;
}
_ => {}
}
Ok(())
}
/// Register a worker
///
/// # Errors
///
/// This function will return an error if fails
#[allow(unused_variables)]
pub async fn register<
A: Serialize + Send + Sync + 'static + for<'de> serde::Deserialize<'de>,
W: BackgroundWorker<A> + 'static,
>(
&self,
worker: W,
) -> Result<()> {
tracing::debug!(worker = W::class_name(), "register worker");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(_, p, _) => {
let mut p = p.lock().await;
p.register(skq::SidekiqBackgroundWorker::new(worker));
}
#[cfg(feature = "bg_pg")]
Self::Postgres(_, registry, _) => {
let mut r = registry.lock().await;
r.register_worker(W::class_name(), worker)?;
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(_, registry, _) => {
let mut r = registry.lock().await;
r.register_worker(W::class_name(), worker)?;
}
_ => {}
}
Ok(())
}
/// Runs the worker loop for this [`Queue`].
///
/// # Errors
///
/// This function will return an error if fails
pub async fn run(&self) -> Result<()> {
tracing::debug!("running background jobs");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(_, p, _) => {
p.lock().await.clone().run().await;
}
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, registry, run_opts) => {
//TODOQ: num workers to config
let handles = registry.lock().await.run(pool, run_opts);
for handle in handles {
handle.await?;
}
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, registry, run_opts) => {
//TODOQ: num workers to config
let handles = registry.lock().await.run(pool, run_opts);
for handle in handles {
handle.await?;
}
}
_ => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
}
}
Ok(())
}
/// Runs the setup of this [`Queue`].
///
/// # Errors
///
/// This function will return an error if fails
pub async fn setup(&self) -> Result<()> {
tracing::debug!("workers setup");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {}
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
pg::initialize_database(pool).await.map_err(Box::from)?;
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
sqlt::initialize_database(pool).await.map_err(Box::from)?;
}
_ => {}
}
Ok(())
}
/// Performs clear on this [`Queue`].
///
/// # Errors
///
/// This function will return an error if fails
pub async fn clear(&self) -> Result<()> {
tracing::debug!("clearing job");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(pool, _, _) => {
skq::clear(pool).await?;
}
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
pg::clear(pool).await.map_err(Box::from)?;
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
sqlt::clear(pool).await.map_err(Box::from)?;
}
_ => {}
}
Ok(())
}
/// Returns a ping of this [`Queue`].
///
/// # Errors
///
/// This function will return an error if fails
pub async fn ping(&self) -> Result<()> {
tracing::debug!("job queue ping requested");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(pool, _, _) => {
skq::ping(pool).await?;
}
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
pg::ping(pool).await.map_err(Box::from)?;
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
sqlt::ping(pool).await.map_err(Box::from)?;
}
_ => {}
}
Ok(())
}
#[must_use]
pub fn describe(&self) -> String {
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => "redis queue".to_string(),
#[cfg(feature = "bg_pg")]
Self::Postgres(_, _, _) => "postgres queue".to_string(),
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(_, _, _) => "sqlite queue".to_string(),
_ => "no queue".to_string(),
}
}
/// # Errors
///
/// Does not currently return an error, but the postgres or other future
/// queue implementations might, so using Result here as return type.
pub fn shutdown(&self) -> Result<()> {
tracing::debug!("waiting for running jobs to finish...");
match self {
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, cancellation_token) => cancellation_token.cancel(),
_ => {}
}
Ok(())
}
async fn get_jobs(
&self,
status: Option<&Vec<JobStatus>>,
age_days: Option<i64>,
) -> Result<serde_json::Value> {
tracing::debug!(status = ?status, age_days = ?age_days, "getting jobs");
match self {
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
let jobs = pg::get_jobs(pool, status, age_days)
.await
.map_err(Box::from)?;
Ok(serde_json::to_value(jobs)?)
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
let jobs = sqlt::get_jobs(pool, status, age_days)
.await
.map_err(Box::from)?;
Ok(serde_json::to_value(jobs)?)
}
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {
tracing::error!("getting jobs for redis provider not implemented");
Err(Error::string(
"getting jobs not supported for redis provider",
))
}
Self::None => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
Err(Error::string("provider not configure"))
}
}
}
/// Cancels jobs based on the given job name for the configured queue provider.
///
/// # Errors
/// - If no queue provider is configured, it will return an error indicating the lack of configuration.
/// - If the Redis provider is selected, it will return an error stating that cancellation is not supported.
/// - Any error in the underlying provider's cancellation logic will propagate from the respective function.
///
pub async fn cancel_jobs(&self, job_name: &str) -> Result<()> {
tracing::debug!(job_name = ?job_name, "cancel jobs");
match self {
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => pg::cancel_jobs_by_name(pool, job_name).await,
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => sqlt::cancel_jobs_by_name(pool, job_name).await,
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {
tracing::error!("canceling jobs for redis provider not implemented");
Err(Error::string(
"canceling jobs not supported for redis provider",
))
}
Self::None => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
Err(Error::string("provider not configure"))
}
}
}
/// Clears jobs older than a specified number of days for the configured queue provider.
///
/// # Errors
/// - If no queue provider is configured, it will return an error indicating the lack of configuration.
/// - If the Redis provider is selected, it will return an error stating that clearing jobs is not supported.
/// - Any error in the underlying provider's job clearing logic will propagate from the respective function.
///
pub async fn clear_jobs_older_than(
&self,
age_days: i64,
status: &Vec<JobStatus>,
) -> Result<()> {
tracing::debug!(age_days = age_days, status = ?status, "cancel jobs with age");
match self {
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => {
pg::clear_jobs_older_than(pool, age_days, Some(status)).await
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => {
sqlt::clear_jobs_older_than(pool, age_days, Some(status)).await
}
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {
tracing::error!("clear jobs for redis provider not implemented");
Err(Error::string("clear jobs not supported for redis provider"))
}
Self::None => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
Err(Error::string("provider not configure"))
}
}
}
/// Clears jobs based on their status for the configured queue provider.
///
/// # Errors
/// - If no queue provider is configured, it will return an error indicating the lack of configuration.
/// - If the Redis provider is selected, it will return an error stating that clearing jobs is not supported.
/// - Any error in the underlying provider's job clearing logic will propagate from the respective function.
pub async fn clear_by_status(&self, status: Vec<JobStatus>) -> Result<()> {
tracing::debug!(status = ?status, "clear jobs by status");
match self {
#[cfg(feature = "bg_pg")]
Self::Postgres(pool, _, _) => pg::clear_by_status(pool, status).await,
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(pool, _, _) => sqlt::clear_by_status(pool, status).await,
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {
tracing::error!("clear jobs for redis provider not implemented");
Err(Error::string("clear jobs not supported for redis provider"))
}
Self::None => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
Err(Error::string("provider not configure"))
}
}
}
/// Dumps the list of jobs to a YAML file at the specified path.
///
/// This function retrieves jobs from the queue, optionally filtered by their status, and
/// writes the job data to a YAML file.
///
/// # Errors
/// - If the specified path cannot be created, an error will be returned.
/// - If the job retrieval or YAML serialization fails, an error will be returned.
/// - If there is an issue creating the dump file, an error will be returned
pub async fn dump(
&self,
path: &Path,
status: Option<&Vec<JobStatus>>,
age_days: Option<i64>,
) -> Result<PathBuf> {
tracing::debug!(path = %path.display(), status = ?status, age_days = ?age_days, "dumping jobs");
if !path.exists() {
tracing::debug!(path = %path.display(), "folder not exists, creating...");
std::fs::create_dir_all(path)?;
}
let dump_file = path.join(format!(
"loco-dump-jobs-{}.yaml",
chrono::Utc::now().format("%Y-%m-%d-%H-%M-%S")
));
let jobs = self.get_jobs(status, age_days).await?;
let data = serde_yaml::to_string(&jobs)?;
let mut file = File::create(&dump_file)?;
file.write_all(data.as_bytes())?;
Ok(dump_file)
}
/// Imports jobs from a YAML file into the configured queue provider.
///
/// This function reads job data from a YAML file located at the specified `path` and imports
/// the jobs into the queue.
///
/// # Errors
/// - If there is an issue opening or reading the YAML file, an error will be returned.
/// - If the queue provider is Redis or none, an error will be returned indicating the lack of support.
/// - If any issues occur while enqueuing the jobs, the function will return an error.
///
pub async fn import(&self, path: &Path) -> Result<()> {
tracing::debug!(path = %path.display(), "import jobs");
match &self {
#[cfg(feature = "bg_pg")]
Self::Postgres(_, _, _) => {
let jobs: Vec<pg::Job> = serde_yaml::from_reader(File::open(path)?)?;
for job in jobs {
self.enqueue(job.name.to_string(), None, job.data).await?;
}
Ok(())
}
#[cfg(feature = "bg_sqlt")]
Self::Sqlite(_, _, _) => {
let jobs: Vec<sqlt::Job> = serde_yaml::from_reader(File::open(path)?)?;
for job in jobs {
self.enqueue(job.name.to_string(), None, job.data).await?;
}
Ok(())
}
#[cfg(feature = "bg_redis")]
Self::Redis(_, _, _) => {
tracing::error!("import jobs for redis provider not implemented");
Err(Error::string(
"getting jobs not supported for redis provider",
))
}
Self::None => {
tracing::error!(
"no queue provider is configured: compile with at least one queue provider \
feature"
);
Err(Error::string("provider not configure"))
}
}
}
}
#[async_trait]
pub trait BackgroundWorker<A: Send + Sync + serde::Serialize + 'static>: Send + Sync {
/// If you have a specific queue
/// in mind and the provider supports custom / priority queues, make your
/// worker return it. Otherwise, return `None`.
#[must_use]
fn queue() -> Option<String> {
None
}
fn build(ctx: &AppContext) -> Self;
#[must_use]
fn class_name() -> String
where
Self: Sized,
{
use heck::ToUpperCamelCase;
let type_name = std::any::type_name::<Self>();
let name = type_name.split("::").last().unwrap_or(type_name);
name.to_upper_camel_case()
}
async fn perform_later(ctx: &AppContext, args: A) -> crate::Result<()>
where
Self: Sized,
{
match &ctx.config.workers.mode {
WorkerMode::BackgroundQueue => {
if let Some(p) = &ctx.queue_provider {
p.enqueue(Self::class_name(), Self::queue(), args).await?;
} else {
tracing::error!(
"perform_later: background queue is selected, but queue was not populated \
in context"
);
}
}
WorkerMode::ForegroundBlocking => {
Self::build(ctx).perform(args).await?;
}
WorkerMode::BackgroundAsync => {
let dx = ctx.clone();
tokio::spawn(async move {
if let Err(err) = Self::build(&dx).perform(args).await {
tracing::error!(err = err.to_string(), "worker failed to perform job");
}
});
}
}
Ok(())
}
async fn perform(&self, args: A) -> crate::Result<()>;
}
/// Initialize the system according to configuration
///
/// # Errors
///
/// This function will return an error if it fails
pub async fn converge(queue: &Queue, config: &QueueConfig) -> Result<()> {
queue.setup().await?;
match config {
QueueConfig::Postgres(PostgresQueueConfig {
dangerously_flush,
uri: _,
max_connections: _,
enable_logging: _,
connect_timeout: _,
idle_timeout: _,
poll_interval_sec: _,
num_workers: _,
min_connections: _,
})
| QueueConfig::Sqlite(SqliteQueueConfig {
dangerously_flush,
uri: _,
max_connections: _,
enable_logging: _,
connect_timeout: _,
idle_timeout: _,
poll_interval_sec: _,
num_workers: _,
min_connections: _,
})
| QueueConfig::Redis(RedisQueueConfig {
dangerously_flush,
uri: _,
queues: _,
num_workers: _,
}) => {
if *dangerously_flush {
queue.clear().await?;
}
}
}
Ok(())
}
/// Create a provider
///
/// # Errors
///
/// This function will return an error if fails to build
#[allow(clippy::missing_panics_doc)]
pub async fn create_queue_provider(config: &Config) -> Result<Option<Arc<Queue>>> {
if config.workers.mode == config::WorkerMode::BackgroundQueue {
if let Some(queue) = &config.queue {
match queue {
// TODOQ call the object inside RedisQueueConfig and pass that
#[cfg(feature = "bg_redis")]
config::QueueConfig::Redis(qcfg) => {
Ok(Some(Arc::new(skq::create_provider(qcfg).await?)))
}
#[cfg(feature = "bg_pg")]
config::QueueConfig::Postgres(qcfg) => {
Ok(Some(Arc::new(pg::create_provider(qcfg).await?)))
}
#[cfg(feature = "bg_sqlt")]
config::QueueConfig::Sqlite(qcfg) => {
Ok(Some(Arc::new(sqlt::create_provider(qcfg).await?)))
}
#[allow(unreachable_patterns)]
_ => Err(Error::string(
"no queue provider feature was selected and compiled, but queue configuration \
is present",
)),
}
} else {
Ok(None)
}
} else {
Ok(None)
}
}
#[cfg(test)]
mod tests {
use std::path::Path;
use insta::assert_debug_snapshot;
use super::*;
use crate::tests_cfg;
fn sqlite_config(db_path: &Path) -> SqliteQueueConfig {
SqliteQueueConfig {
uri: format!(
"sqlite://{}?mode=rwc",
db_path.join("sample.sqlite").display()
),
dangerously_flush: false,
enable_logging: false,
max_connections: 1,
min_connections: 1,
connect_timeout: 500,
idle_timeout: 500,
poll_interval_sec: 1,
num_workers: 1,
}
}
#[tokio::test]
async fn can_dump_jobs() {
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.create()
.expect("create temp folder");
let qcfg = sqlite_config(tree_fs.root.as_path());
let queue = sqlt::create_provider(&qcfg)
.await
.expect("create sqlite queue");
let pool = sqlx::SqlitePool::connect(&qcfg.uri)
.await
.expect("connect to sqlite db");
queue.setup().await.expect("setup sqlite db");
tests_cfg::queue::sqlite_seed_data(&pool).await;
let dump_file = queue
.dump(
tree_fs.root.as_path(),
Some(&vec![JobStatus::Failed, JobStatus::Cancelled]),
None,
)
.await
.expect("dump jobs");
assert_debug_snapshot!(std::fs::read_to_string(dump_file));
}
#[tokio::test]
async fn cat_import_jobs_form_file() {
let tree_fs = tree_fs::TreeBuilder::default()
.drop(true)
.create()
.expect("create temp folder");
let qcfg = sqlite_config(tree_fs.root.as_path());
let queue = sqlt::create_provider(&qcfg)
.await
.expect("create sqlite queue");
let pool = sqlx::SqlitePool::connect(&qcfg.uri)
.await
.expect("connect to sqlite db");
queue.setup().await.expect("setup sqlite db");
let count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM sqlt_loco_queue")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(count, 0);
queue
.import(
PathBuf::from("tests")
.join("fixtures")
.join("queue")
.join("jobs.yaml")
.as_path(),
)
.await
.expect("dump import");
let count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM sqlt_loco_queue")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(count, 14);
}
}