Don't generate default task unique hashes
This commit is contained in:
parent
894f928c01
commit
0fbc67052a
4 changed files with 7 additions and 26 deletions
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
authors = [
|
||||
"Rafael Caricio <rafael@caricio.com>",
|
||||
]
|
||||
description = "Async background job processing library with Diesel and Tokio"
|
||||
description = "Async background task processing library with Tokio and Postgres"
|
||||
repository = "https://code.caric.io/rafaelcaricio/backie"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -15,13 +15,10 @@ rust-version = "1.67"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
cron = "0.12"
|
||||
chrono = "0.4"
|
||||
hex = "0.4"
|
||||
log = "0.4"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
sha2 = "0.10"
|
||||
anyhow = "1"
|
||||
thiserror = "1"
|
||||
uuid = { version = "1.1", features = ["v4", "serde"] }
|
||||
|
|
10
src/store.rs
10
src/store.rs
|
@ -100,19 +100,11 @@ pub mod test_store {
|
|||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
pub struct MemoryTaskStore {
|
||||
tasks: Arc<Mutex<BTreeMap<TaskId, Task>>>,
|
||||
}
|
||||
|
||||
impl MemoryTaskStore {
|
||||
pub fn new() -> Self {
|
||||
MemoryTaskStore {
|
||||
tasks: Arc::new(Mutex::new(BTreeMap::new())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl TaskStore for MemoryTaskStore {
|
||||
async fn pull_next_task(&self, queue_name: &str) -> Result<Option<Task>, AsyncQueueError> {
|
||||
|
|
14
src/task.rs
14
src/task.rs
|
@ -5,7 +5,6 @@ use chrono::Utc;
|
|||
use diesel::prelude::*;
|
||||
use diesel_derive_newtype::DieselNewType;
|
||||
use serde::Serialize;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::fmt::Display;
|
||||
|
@ -41,15 +40,8 @@ impl Display for TaskId {
|
|||
pub struct TaskHash(Cow<'static, str>);
|
||||
|
||||
impl TaskHash {
|
||||
pub fn default_for_task<T>(value: &T) -> Result<Self, serde_json::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let value = serde_json::to_value(value)?;
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(serde_json::to_string(&value)?.as_bytes());
|
||||
let result = hasher.finalize();
|
||||
Ok(TaskHash(Cow::from(hex::encode(result))))
|
||||
pub fn new<T: Into<String>>(hash: T) -> Self {
|
||||
TaskHash(Cow::Owned(hash.into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +166,7 @@ pub struct CurrentTask {
|
|||
impl CurrentTask {
|
||||
pub(crate) fn new(task: &Task) -> Self {
|
||||
Self {
|
||||
id: task.id.clone(),
|
||||
id: task.id,
|
||||
retries: task.retries,
|
||||
created_at: task.created_at,
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ where
|
|||
let mut worker: Worker<AppData, S> = Worker::new(
|
||||
self.task_store.clone(),
|
||||
queue_name.clone(),
|
||||
retention_mode.clone(),
|
||||
*retention_mode,
|
||||
self.task_registry.clone(),
|
||||
self.application_data_fn.clone(),
|
||||
Some(rx.clone()),
|
||||
|
@ -284,7 +284,7 @@ mod tests {
|
|||
}
|
||||
|
||||
async fn memory_store() -> MemoryTaskStore {
|
||||
MemoryTaskStore::new()
|
||||
MemoryTaskStore::default()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
Loading…
Reference in a new issue