Skip to content

Commit

Permalink
fix: Allow cargo build --all-features (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Nov 15, 2023
1 parent 00520f6 commit dd75509
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/apalis-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl JobContext {
status: JobState::Pending,
#[cfg(feature = "chrono")]
run_at: chrono::Utc::now(),
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
run_at: time::OffsetDateTime::now_utc(),
lock_at: None,
done_at: None,
Expand Down
2 changes: 1 addition & 1 deletion packages/apalis-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,5 @@ use time::OffsetDateTime;

#[cfg(feature = "chrono")]
type Timestamp = DateTime<Utc>;
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
type Timestamp = OffsetDateTime;
2 changes: 1 addition & 1 deletion packages/apalis-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub use storage::RedisStorage;

#[cfg(feature = "chrono")]
type Timestamp = chrono::DateTime<chrono::Utc>;
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
type Timestamp = time::OffsetDateTime;
4 changes: 2 additions & 2 deletions packages/apalis-redis/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ where

#[cfg(feature = "chrono")]
let timestamp = on.timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let timestamp = on.unix_timestamp();

schedule_job
Expand Down Expand Up @@ -793,7 +793,7 @@ pub mod expose {
.map(|w| {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();
ExposedWorker::new::<Self, T>(
WorkerId::new(
Expand Down
2 changes: 1 addition & 1 deletion packages/apalis-sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ use time::OffsetDateTime;
#[cfg(feature = "chrono")]
#[allow(dead_code)]
type Timestamp = DateTime<Utc>;
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
#[allow(dead_code)]
type Timestamp = OffsetDateTime;
14 changes: 7 additions & 7 deletions packages/apalis-sql/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
SET status = "Pending", done_at = NULL, lock_by = NULL, lock_at = NULL, last_error ="Job was abandoned";"#;
#[cfg(feature = "chrono")]
let five_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(5);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let five_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(5);
sqlx::query(query)
.bind(five_minutes_ago)
Expand Down Expand Up @@ -333,7 +333,7 @@ where
.map_err(|e| StorageError::Database(Box::new(e)))?;
#[cfg(feature = "chrono")]
let wait = chrono::Duration::seconds(wait);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let wait = time::Duration::seconds(wait);
let mut tx = pool
.acquire()
Expand All @@ -343,7 +343,7 @@ where
"UPDATE jobs SET status = 'Pending', done_at = NULL, lock_by = NULL, lock_at = NULL, run_at = ? WHERE id = ?";
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();
sqlx::query(query)
.bind(now.add(wait))
Expand Down Expand Up @@ -390,7 +390,7 @@ where
async fn keep_alive<Service>(&mut self, worker_id: &WorkerId) -> StorageResult<()> {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

self.keep_alive_at::<Service>(worker_id, now).await
Expand Down Expand Up @@ -571,7 +571,7 @@ mod tests {
async fn register_worker(storage: &mut MysqlStorage<Email>) -> WorkerId {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

register_worker_at(storage, now).await
Expand Down Expand Up @@ -670,7 +670,7 @@ mod tests {
let worker_id = WorkerId::new("test_worker");
#[cfg(feature = "chrono")]
let six_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(6);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let six_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(6);

storage
Expand Down Expand Up @@ -713,7 +713,7 @@ mod tests {
// register a worker responding at 4 minutes ago
#[cfg(feature = "chrono")]
let four_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(4);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let four_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(4);

let worker_id = WorkerId::new("test_worker");
Expand Down
12 changes: 6 additions & 6 deletions packages/apalis-sql/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where
.map_err(|e| StorageError::Database(Box::new(e)))?;
#[cfg(feature = "chrono")]
let wait = chrono::Duration::seconds(wait);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let wait = time::Duration::seconds(wait);

let mut tx = pool
Expand All @@ -337,7 +337,7 @@ where

#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

sqlx::query(query)
Expand Down Expand Up @@ -385,7 +385,7 @@ where
async fn keep_alive<Service>(&mut self, worker_id: &WorkerId) -> StorageResult<()> {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

self.keep_alive_at::<Service>(worker_id, now).await
Expand Down Expand Up @@ -576,7 +576,7 @@ mod tests {
async fn register_worker(storage: &mut PostgresStorage<Email>) -> WorkerId {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

register_worker_at(storage, now).await
Expand Down Expand Up @@ -669,7 +669,7 @@ mod tests {

#[cfg(feature = "chrono")]
let six_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(6);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let six_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(6);

let worker_id = register_worker_at(&mut storage, six_minutes_ago).await;
Expand Down Expand Up @@ -704,7 +704,7 @@ mod tests {

#[cfg(feature = "chrono")]
let four_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(4);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let four_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(4);

let worker_id = register_worker_at(&mut storage, four_minutes_ago).await;
Expand Down
26 changes: 13 additions & 13 deletions packages/apalis-sql/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<T: Job> SqliteStorage<T> {
UPDATE SET last_seen = EXCLUDED.last_seen";
#[cfg(feature = "chrono")]
let last_seen = last_seen.timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let last_seen = last_seen.unix_timestamp();
sqlx::query(query)
.bind(worker_id.to_string())
Expand Down Expand Up @@ -119,7 +119,7 @@ where
Some(job) => {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now().timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc().unix_timestamp();

let job_id = job.id();
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<T: DeserializeOwned + Send + Unpin + Job> SqliteStorage<T> {
let mut tx = tx.acquire().await.map_err(|e| JobStreamError::BrokenPipe(Box::from(e)))?;
#[cfg(feature = "chrono")]
let now = chrono::Utc::now().timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc().unix_timestamp();
let job_type = T::NAME;
let fetch_query = "SELECT * FROM Jobs
Expand Down Expand Up @@ -209,7 +209,7 @@ where

#[cfg(feature = "chrono")]
let on = on.timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let on = on.unix_timestamp();

let job = serde_json::to_string(&job).map_err(|e| StorageError::Parse(e.into()))?;
Expand Down Expand Up @@ -277,7 +277,7 @@ where
#[cfg(feature = "chrono")]
let five_minutes_ago =
(chrono::Utc::now() - chrono::Duration::minutes(5)).timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let five_minutes_ago =
(time::OffsetDateTime::now_utc() - time::Duration::minutes(5)).unix_timestamp();
sqlx::query(query)
Expand Down Expand Up @@ -374,7 +374,7 @@ where
.map_err(|e| StorageError::Database(Box::new(e)))?;
#[cfg(feature = "chrono")]
let wait = chrono::Duration::seconds(wait);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let wait = time::Duration::seconds(wait);
let mut tx = pool
.acquire()
Expand All @@ -384,7 +384,7 @@ where
"UPDATE Jobs SET status = 'Failed', done_at = NULL, lock_by = NULL, lock_at = NULL, run_at = ?2 WHERE id = ?1";
#[cfg(feature = "chrono")]
let wait_until = chrono::Utc::now().add(wait).timestamp();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let wait_until = time::OffsetDateTime::now_utc().add(wait).unix_timestamp();
sqlx::query(query)
.bind(job_id.to_string())
Expand All @@ -405,12 +405,12 @@ where
let attempts = job.attempts();
#[cfg(feature = "chrono")]
let done_at = (*job.done_at()).map(|v| v.timestamp());
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let done_at = (*job.done_at()).map(|v| v.unix_timestamp());
let lock_by = job.lock_by().clone();
#[cfg(feature = "chrono")]
let lock_at = (*job.lock_at()).map(|v| v.timestamp());
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let lock_at = (*job.lock_at()).map(|v| v.unix_timestamp());
let last_error = job.last_error().clone();

Expand All @@ -437,7 +437,7 @@ where
async fn keep_alive<Service>(&mut self, worker_id: &WorkerId) -> StorageResult<()> {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

self.keep_alive_at::<Service>(worker_id, now).await
Expand Down Expand Up @@ -598,7 +598,7 @@ mod tests {
async fn register_worker(storage: &mut SqliteStorage<Email>) -> WorkerId {
#[cfg(feature = "chrono")]
let now = chrono::Utc::now();
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let now = time::OffsetDateTime::now_utc();

register_worker_at(storage, now).await
Expand Down Expand Up @@ -685,7 +685,7 @@ mod tests {

#[cfg(feature = "chrono")]
let six_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(6);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let six_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(6);

let worker_id = register_worker_at(&mut storage, six_minutes_ago).await;
Expand Down Expand Up @@ -718,7 +718,7 @@ mod tests {

#[cfg(feature = "chrono")]
let four_minutes_ago = chrono::Utc::now() - chrono::Duration::minutes(4);
#[cfg(feature = "time")]
#[cfg(all(not(feature = "chrono"), feature = "time"))]
let four_minutes_ago = time::OffsetDateTime::now_utc() - time::Duration::minutes(4);

let worker_id = register_worker_at(&mut storage, four_minutes_ago).await;
Expand Down

0 comments on commit dd75509

Please sign in to comment.