From ba1a9f422fb861d10c55741acc91cf1baea253de Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 23 Apr 2020 13:16:56 -0500 Subject: [PATCH] Remove dependency on Actix Actors --- examples/actix-example/Cargo.toml | 1 - jobs-actix/Cargo.toml | 5 ++--- jobs-actix/src/every.rs | 8 ++++++-- jobs-actix/src/lib.rs | 7 +++---- jobs-actix/src/server.rs | 8 ++++++-- jobs-actix/src/worker.rs | 3 ++- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/examples/actix-example/Cargo.toml b/examples/actix-example/Cargo.toml index 68b37db..68d723e 100644 --- a/examples/actix-example/Cargo.toml +++ b/examples/actix-example/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix = "0.10.0-alpha.2" actix-rt = "1.0.0" anyhow = "1.0" async-trait = "0.1.24" diff --git a/jobs-actix/Cargo.toml b/jobs-actix/Cargo.toml index 3242d5a..a80595b 100644 --- a/jobs-actix/Cargo.toml +++ b/jobs-actix/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "background-jobs-actix" description = "in-process jobs processor based on Actix" -version = "0.8.0-alpha.1" +version = "0.8.0-alpha.2" license-file = "../LICENSE" authors = ["asonix "] repository = "https://git.asonix.dog/Aardwolf/background-jobs" @@ -10,8 +10,7 @@ readme = "../README.md" edition = "2018" [dependencies] -actix = "0.10.0-alpha.2" -actix-rt = "1.0.0" +actix-rt = "1.1.0" anyhow = "1.0" async-trait = "0.1.24" background-jobs-core = { version = "0.8.0-alpha.0", path = "../jobs-core", features = ["with-actix"] } diff --git a/jobs-actix/src/every.rs b/jobs-actix/src/every.rs index 5d40a22..0633a93 100644 --- a/jobs-actix/src/every.rs +++ b/jobs-actix/src/every.rs @@ -1,6 +1,10 @@ use crate::{Job, QueueHandle}; -use actix::clock::{interval_at, Duration, Instant}; +use actix_rt::{ + spawn, + time::{interval_at, Instant}, +}; use log::error; +use std::time::Duration; /// A type used to schedule recurring jobs. /// @@ -12,7 +16,7 @@ pub(crate) fn every(spawner: QueueHandle, duration: Duration, job: J) where J: Job + Clone, { - actix::spawn(async move { + spawn(async move { let mut interval = interval_at(Instant::now(), duration); loop { diff --git a/jobs-actix/src/lib.rs b/jobs-actix/src/lib.rs index b12bf9c..9fd00f3 100644 --- a/jobs-actix/src/lib.rs +++ b/jobs-actix/src/lib.rs @@ -12,7 +12,6 @@ //! //! ### Example //! ```rust,ignore -//! use actix::System; //! use anyhow::Error; //! use background_jobs::{create_server, Backoff, Job, MaxRetries, WorkerConfig}; //! use futures::future::{ok, Ready}; @@ -117,7 +116,7 @@ //! } //! ``` -use actix::Arbiter; +use actix_rt::{spawn, Arbiter}; use anyhow::Error; use background_jobs_core::{new_job, new_scheduled_job, Job, ProcessorMap, Stats, Storage}; use chrono::{DateTime, Utc}; @@ -253,7 +252,7 @@ impl QueueHandle { { let job = new_job(job)?; let server = self.inner.clone(); - actix::spawn(async move { + spawn(async move { if let Err(e) = server.new_job(job).await { error!("Error creating job, {}", e); } @@ -271,7 +270,7 @@ impl QueueHandle { { let job = new_scheduled_job(job, after)?; let server = self.inner.clone(); - actix::spawn(async move { + spawn(async move { if let Err(e) = server.new_job(job).await { error!("Error creating job, {}", e); } diff --git a/jobs-actix/src/server.rs b/jobs-actix/src/server.rs index 0bbcf76..aad478f 100644 --- a/jobs-actix/src/server.rs +++ b/jobs-actix/src/server.rs @@ -2,13 +2,17 @@ use crate::{ storage::{ActixStorage, StorageWrapper}, worker::Worker, }; -use actix::clock::{interval_at, Duration, Instant}; +use actix_rt::{ + spawn, + time::{interval_at, Instant}, +}; use anyhow::Error; use background_jobs_core::{NewJobInfo, ReturnJobInfo, Stats, Storage}; use log::{error, trace}; use std::{ collections::{HashMap, VecDeque}, sync::Arc, + time::Duration, }; use tokio::sync::Mutex; @@ -39,7 +43,7 @@ impl Server { }; let server2 = server.clone(); - actix::spawn(async move { + spawn(async move { let mut interval = interval_at(Instant::now(), Duration::from_secs(1)); loop { diff --git a/jobs-actix/src/worker.rs b/jobs-actix/src/worker.rs index 8585e58..d731816 100644 --- a/jobs-actix/src/worker.rs +++ b/jobs-actix/src/worker.rs @@ -1,4 +1,5 @@ use crate::Server; +use actix_rt::spawn; use background_jobs_core::{CachedProcessorMap, JobInfo}; use log::{debug, error, warn}; use tokio::sync::mpsc::{channel, Sender}; @@ -58,7 +59,7 @@ pub(crate) fn local_worker( queue: queue.clone(), }; - actix::spawn(async move { + spawn(async move { debug!("Beginning worker loop for {}", id); if let Err(e) = server.request_job(Box::new(handle.clone())).await { error!("Couldn't request first job, bailing, {}", e);