Skip to content

Commit

Permalink
also make schedule methods pass input by reference (#34)
Browse files Browse the repository at this point in the history
This is a follow up to the enqueue changes in #33.
  • Loading branch information
maxcountryman authored Oct 26, 2024
1 parent 6df1f0e commit 6d07fb4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/graceful_shutdown/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;

let every_second = "* * * * * *[America/Los_Angeles]".parse()?;
job.schedule(every_second, ()).await?;
job.schedule(&every_second, &()).await?;

// Await the shutdown signal handler in its own task.
tokio::spawn(async move { shutdown_signal(&pool).await });
Expand Down
2 changes: 1 addition & 1 deletion examples/scheduled/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Schedule the job to run every minute in the given time zone.
let every_minute = "0 * * * * *[America/Los_Angeles]".parse()?;
job.schedule(every_minute, ()).await?;
job.schedule(&every_minute, &()).await?;

job.run().await?;

Expand Down
14 changes: 7 additions & 7 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@
//!
//! // Sets a weekly schedule with the given input.
//! let weekly = "@weekly[America/Los_Angeles]".parse()?;
//! job.schedule(weekly, ()).await?;
//! job.schedule(&weekly, &()).await?;
//!
//! job.start();
//! # Ok::<(), Box<dyn std::error::Error>>(())
Expand Down Expand Up @@ -805,7 +805,7 @@ where
}

/// Schedule the job using a connection from the queue's pool.
pub async fn schedule(&self, zoned_schedule: ZonedSchedule, input: I) -> Result {
pub async fn schedule(&self, zoned_schedule: &ZonedSchedule, input: &I) -> Result {
let mut conn = self.queue.pool.acquire().await?;
self.schedule_using(&mut *conn, zoned_schedule, input).await
}
Expand All @@ -817,15 +817,15 @@ where
pub async fn schedule_using<'a, E>(
&self,
executor: E,
zoned_schedule: ZonedSchedule,
input: I,
zoned_schedule: &ZonedSchedule,
input: &I,
) -> Result
where
E: PgExecutor<'a>,
{
let job_input = self.first_job_input(&input)?;
let job_input = self.first_job_input(input)?;
self.queue
.schedule(executor, zoned_schedule, job_input)
.schedule(executor, zoned_schedule, &job_input)
.await?;

Ok(())
Expand Down Expand Up @@ -1626,7 +1626,7 @@ mod tests {
let monthly = "@monthly[America/Los_Angeles]"
.parse()
.expect("A valid zoned scheduled should be provided");
job.schedule(monthly, ()).await?;
job.schedule(&monthly, &()).await?;

let (schedule, _) = queue
.task_schedule(&pool)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
//!
//! // Set a daily schedule with the given input.
//! let daily = "@daily[America/Los_Angeles]".parse()?;
//! job.schedule(daily, DailyReport).await?;
//! job.schedule(&daily, &DailyReport).await?;
//!
//! // Start processing enqueued jobs.
//! job.start().await??;
Expand Down
8 changes: 4 additions & 4 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
//!
//! // Set a quarter-hour schedule; IANA timezones are mandatory.
//! let quarter_hour = "0 */15 * * * *[America/Los_Angeles]".parse()?;
//! queue.schedule(&pool, quarter_hour, ()).await?;
//! queue.schedule(&pool, &quarter_hour, &()).await?;
//!
//! # /*
//! let task = { /* A type that implements `Task`. */ };
Expand Down Expand Up @@ -518,13 +518,13 @@ impl<T: Task> Queue<T> {
pub async fn schedule<'a, E>(
&self,
executor: E,
zoned_schedule: ZonedSchedule,
input: T::Input,
zoned_schedule: &ZonedSchedule,
input: &T::Input,
) -> Result
where
E: PgExecutor<'a>,
{
let input_value = serde_json::to_value(&input)?;
let input_value = serde_json::to_value(input)?;

sqlx::query!(
r#"
Expand Down

0 comments on commit 6d07fb4

Please sign in to comment.