feat: add pause/resume job functionality
- Added Redis paused set for job management - Worker skips paused jobs during polling - Added POST /api/v1/jobs/:uuid/pause endpoint - Added POST /api/v1/jobs/:uuid/resume endpoint - Added GET /api/v1/jobs/paused endpoint - Paused jobs are excluded from worker processing queue
This commit is contained in:
@@ -470,13 +470,31 @@ impl JobWorker {
|
||||
}
|
||||
}
|
||||
|
||||
// Get paused job UUIDs from Redis
|
||||
let paused_key = format!("{}jobs:paused", crate::core::config::REDIS_KEY_PREFIX.as_str());
|
||||
let paused_jobs: std::collections::HashSet<String> = if let Ok(mut conn) = self.redis.get_conn().await {
|
||||
redis::cmd("SMEMBERS")
|
||||
.arg(&paused_key)
|
||||
.query_async(&mut conn)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
std::collections::HashSet::new()
|
||||
};
|
||||
|
||||
// Process pending jobs if any
|
||||
let pending_jobs = self.db.get_pending_jobs(self.config.batch_size).await?;
|
||||
|
||||
if !pending_jobs.is_empty() {
|
||||
info!("Found {} pending jobs", pending_jobs.len());
|
||||
info!("Found {} pending jobs ({} paused)", pending_jobs.len(), paused_jobs.len());
|
||||
|
||||
for job in pending_jobs {
|
||||
// Skip paused jobs
|
||||
if paused_jobs.contains(&job.uuid) {
|
||||
debug!("Skipping paused job: {}", job.uuid);
|
||||
continue;
|
||||
}
|
||||
|
||||
if !self.processor_pool.can_start_for_job(job.id).await {
|
||||
info!("Max concurrent processors reached, waiting...");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user