Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enqueue a sched job if the worker removed it #51

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/periodic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl Builder {
..Default::default()
};

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

pj.hydrate_attributes()?;
Expand Down
2 changes: 1 addition & 1 deletion src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl RedisConnection {
.await
}

pub async fn zrem<V>(&mut self, key: String, value: V) -> Result<bool, RedisError>
pub async fn zrem<V>(&mut self, key: String, value: V) -> Result<usize, RedisError>
where
V: ToRedisArgs + Send + Sync,
{
Expand Down
8 changes: 4 additions & 4 deletions src/scheduled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ impl Scheduled {
let mut redis = self.redis.get().await?;

let jobs: Vec<String> = redis
.zrangebyscore_limit(sorted_set.clone(), "-inf", now.timestamp(), 0, 100)
.zrangebyscore_limit(sorted_set.clone(), "-inf", now.timestamp(), 0, 10)
.await?;

n += jobs.len();

for job in jobs {
if redis.zrem(sorted_set.clone(), job.clone()).await? {
if redis.zrem(sorted_set.clone(), job.clone()).await? > 0 {
let work = UnitOfWork::from_job_string(job)?;

debug!({
Expand All @@ -36,6 +34,8 @@ impl Scheduled {
}, "Enqueueing job");

work.enqueue_direct(&mut redis).await?;

n += 1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl StatsPublisher {
.arg(stats.beat.timestamp())
.arg("info")
.arg(serde_json::to_string(&stats.info)?)
.query_async(conn.unnamespaced_borrow_mut())
.query_async::<_, ()>(conn.unnamespaced_borrow_mut())
.await?;

conn.expire(self.identity.clone(), 30).await?;
Expand Down
Loading