Skip to content

Commit

Permalink
Retry can be boolean or a number
Browse files Browse the repository at this point in the history
Leave it as a JsonValue for now for better compatibility
  • Loading branch information
Antti committed Sep 24, 2024
1 parent c1822b7 commit f1306a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ pub type Result<T> = std::result::Result<T, Error>;
pub fn opts() -> EnqueueOpts {
EnqueueOpts {
queue: "default".into(),
retry: true,
retry: JsonValue::Bool(true),
unique_for: None,
}
}

pub struct EnqueueOpts {
queue: String,
retry: bool,
retry: JsonValue,
unique_for: Option<std::time::Duration>,
}

Expand All @@ -78,7 +78,7 @@ impl EnqueueOpts {
}

#[must_use]
pub fn retry(self, retry: bool) -> Self {
pub fn retry(self, retry: JsonValue) -> Self {
Self { retry, ..self }
}

Expand Down Expand Up @@ -106,7 +106,7 @@ impl EnqueueOpts {
jid: new_jid(),
created_at: chrono::Utc::now().timestamp() as f64,
enqueued_at: None,
retry: self.retry,
retry: self.retry.clone(),
args,

// Make default eventually...
Expand Down Expand Up @@ -178,7 +178,7 @@ fn new_jid() -> String {

pub struct WorkerOpts<Args, W: Worker<Args> + ?Sized> {
queue: String,
retry: bool,
retry: JsonValue,
args: PhantomData<Args>,
worker: PhantomData<W>,
unique_for: Option<std::time::Duration>,
Expand All @@ -192,15 +192,15 @@ where
pub fn new() -> Self {
Self {
queue: "default".into(),
retry: true,
retry: JsonValue::Bool(true),
args: PhantomData,
worker: PhantomData,
unique_for: None,
}
}

#[must_use]
pub fn retry(self, retry: bool) -> Self {
pub fn retry(self, retry: JsonValue) -> Self {
Self { retry, ..self }
}

Expand Down Expand Up @@ -250,7 +250,7 @@ where
impl<Args, W: Worker<Args>> From<&WorkerOpts<Args, W>> for EnqueueOpts {
fn from(opts: &WorkerOpts<Args, W>) -> Self {
Self {
retry: opts.retry,
retry: opts.retry.clone(),
queue: opts.queue.clone(),
unique_for: opts.unique_for,
}
Expand Down Expand Up @@ -410,7 +410,7 @@ impl WorkerRef {
pub struct Job {
pub queue: String,
pub args: JsonValue,
pub retry: bool,
pub retry: JsonValue,
pub class: String,
pub jid: String,
pub created_at: f64,
Expand Down
10 changes: 5 additions & 5 deletions src/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Builder {
pub(crate) name: Option<String>,
pub(crate) queue: Option<String>,
pub(crate) args: Option<JsonValue>,
pub(crate) retry: Option<bool>,
pub(crate) retry: Option<JsonValue>,
pub(crate) cron: Cron,
}

Expand Down Expand Up @@ -66,7 +66,7 @@ impl Builder {
}

#[must_use]
pub fn retry(self, retry: bool) -> Self {
pub fn retry(self, retry: JsonValue) -> Self {
Self {
retry: Some(retry),
..self
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Builder {
..Default::default()
};

pj.retry = self.retry;
pj.retry = self.retry.clone();
pj.queue = self.queue.clone();
pj.args = self.args.clone().map(|a| a.to_string());

Expand All @@ -117,7 +117,7 @@ pub struct PeriodicJob {
pub(crate) cron: String,
pub(crate) queue: Option<String>,
pub(crate) args: Option<String>,
retry: Option<bool>,
retry: Option<JsonValue>,

#[serde(skip)]
cron_schedule: Option<Cron>,
Expand Down Expand Up @@ -191,7 +191,7 @@ impl PeriodicJob {
jid: new_jid(),
created_at: chrono::Utc::now().timestamp() as f64,
enqueued_at: None,
retry: self.retry.unwrap_or(false),
retry: self.retry.clone().unwrap_or(JsonValue::Bool(false)),
args,

// Make default eventually...
Expand Down
2 changes: 1 addition & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl StatsPublisher {
pub async fn publish_stats(&self, redis: RedisPool) -> Result<(), Box<dyn std::error::Error>> {
let stats = self.create_process_stats().await?;
let mut conn = redis.get().await?;
conn.cmd_with_key("HSET", self.identity.clone())
let _ : () = conn.cmd_with_key("HSET", self.identity.clone())
.arg("rss")
.arg(stats.rss)
.arg("rtt_us")
Expand Down

0 comments on commit f1306a8

Please sign in to comment.