Skip to content

Commit 7af5a0f

Browse files
committed
Fix formatting
1 parent 1247fb1 commit 7af5a0f

File tree

17 files changed

+381
-309
lines changed

17 files changed

+381
-309
lines changed

cargo-hammerwork/src/commands/workflow.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,13 @@ impl WorkflowCommand {
563563
.filter_map(|dep_id| {
564564
if let Some(dep_job) = job_map.get(dep_id) {
565565
if !visited.contains(dep_id) {
566-
Self::calculate_job_level(dep_job, job_map, levels, visited, _current_level);
566+
Self::calculate_job_level(
567+
dep_job,
568+
job_map,
569+
levels,
570+
visited,
571+
_current_level,
572+
);
567573
}
568574
levels.get(dep_id).copied()
569575
} else {

cargo-hammerwork/src/config/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ use std::path::PathBuf;
118118
pub struct Config {
119119
/// Database connection URL (e.g., "postgresql://localhost/hammerwork")
120120
pub database_url: Option<String>,
121-
121+
122122
/// Default queue name for operations
123123
pub default_queue: Option<String>,
124-
124+
125125
/// Default limit for list operations
126126
pub default_limit: Option<u32>,
127-
127+
128128
/// Log level (error, warn, info, debug, trace)
129129
pub log_level: Option<String>,
130-
130+
131131
/// Database connection pool size
132132
pub connection_pool_size: Option<u32>,
133133
}

cargo-hammerwork/src/utils/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//!
2222
//! // Connect to MySQL
2323
//! let mysql_pool = DatabasePool::connect(
24-
//! "mysql://localhost/hammerwork",
24+
//! "mysql://localhost/hammerwork",
2525
//! 5
2626
//! ).await?;
2727
//! # Ok(())

cargo-hammerwork/src/utils/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use std::fmt;
7070
/// use cargo_hammerwork::utils::display::JobTable;
7171
///
7272
/// let mut table = JobTable::new();
73-
///
73+
///
7474
/// // Add multiple jobs
7575
/// table.add_job_row(
7676
/// "job-id-1", "email", "pending", "normal", 0,
@@ -80,7 +80,7 @@ use std::fmt;
8080
/// "job-id-2", "data-processing", "running", "high", 1,
8181
/// "2024-01-01 09:55:00", "2024-01-01 10:00:00"
8282
/// );
83-
///
83+
///
8484
/// // The table will display with color-coded status and priority
8585
/// ```
8686
pub struct JobTable {
@@ -189,7 +189,7 @@ impl fmt::Display for JobTable {
189189
/// stats.add_stats_row("pending", "normal", 100);
190190
/// stats.add_stats_row("running", "high", 10);
191191
/// stats.add_stats_row("failed", "critical", 2);
192-
///
192+
///
193193
/// // Display shows icons: 🟡 pending, 🔵 running, 🔴 failed
194194
/// ```
195195
pub struct StatsTable {

hammerwork-web/src/api/jobs.rs

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
//! ```
8080
8181
use super::{
82-
with_filters, with_pagination, with_sort, ApiResponse, FilterParams,
83-
PaginatedResponse, PaginationMeta, PaginationParams, SortParams,
82+
ApiResponse, FilterParams, PaginatedResponse, PaginationMeta, PaginationParams, SortParams,
83+
with_filters, with_pagination, with_sort,
8484
};
8585
use hammerwork::queue::DatabaseQueue;
8686
use serde::{Deserialize, Serialize};
@@ -226,29 +226,27 @@ where
226226
// For now, return a placeholder response
227227
// In a real implementation, this would query the database with filters and pagination
228228
let _ = (queue, filters, sort);
229-
230-
let mock_jobs = vec![
231-
JobInfo {
232-
id: "job-1".to_string(),
233-
queue_name: "default".to_string(),
234-
status: "pending".to_string(),
235-
priority: "normal".to_string(),
236-
attempts: 0,
237-
max_attempts: 3,
238-
payload: serde_json::json!({"task": "send_email", "to": "[email protected]"}),
239-
created_at: chrono::Utc::now(),
240-
scheduled_at: chrono::Utc::now(),
241-
started_at: None,
242-
completed_at: None,
243-
failed_at: None,
244-
error_message: None,
245-
processing_time_ms: None,
246-
cron_schedule: None,
247-
is_recurring: false,
248-
trace_id: None,
249-
correlation_id: None,
250-
},
251-
];
229+
230+
let mock_jobs = vec![JobInfo {
231+
id: "job-1".to_string(),
232+
queue_name: "default".to_string(),
233+
status: "pending".to_string(),
234+
priority: "normal".to_string(),
235+
attempts: 0,
236+
max_attempts: 3,
237+
payload: serde_json::json!({"task": "send_email", "to": "[email protected]"}),
238+
created_at: chrono::Utc::now(),
239+
scheduled_at: chrono::Utc::now(),
240+
started_at: None,
241+
completed_at: None,
242+
failed_at: None,
243+
error_message: None,
244+
processing_time_ms: None,
245+
cron_schedule: None,
246+
is_recurring: false,
247+
trace_id: None,
248+
correlation_id: None,
249+
}];
252250

253251
let response = PaginatedResponse {
254252
items: mock_jobs,
@@ -277,8 +275,7 @@ where
277275
_ => JobPriority::Normal,
278276
};
279277

280-
let mut job = Job::new(request.queue_name, request.payload)
281-
.with_priority(priority);
278+
let mut job = Job::new(request.queue_name, request.payload).with_priority(priority);
282279

283280
if let Some(scheduled_at) = request.scheduled_at {
284281
job.scheduled_at = scheduled_at;
@@ -312,10 +309,7 @@ where
312309
}
313310

314311
/// Handler for getting a specific job
315-
async fn get_job_handler<T>(
316-
job_id: String,
317-
queue: Arc<T>,
318-
) -> Result<impl Reply, warp::Rejection>
312+
async fn get_job_handler<T>(job_id: String, queue: Arc<T>) -> Result<impl Reply, warp::Rejection>
319313
where
320314
T: DatabaseQueue + Send + Sync,
321315
{
@@ -343,10 +337,12 @@ where
343337
completed_at: job.completed_at,
344338
failed_at: job.failed_at,
345339
error_message: job.error_message.clone(),
346-
processing_time_ms: job.started_at.and_then(|start|
347-
job.completed_at.or(job.failed_at).or(job.timed_out_at)
340+
processing_time_ms: job.started_at.and_then(|start| {
341+
job.completed_at
342+
.or(job.failed_at)
343+
.or(job.timed_out_at)
348344
.map(|end| (end - start).num_milliseconds())
349-
),
345+
}),
350346
cron_schedule: job.cron_schedule.clone(),
351347
is_recurring: job.is_recurring(),
352348
trace_id: job.trace_id.clone(),
@@ -384,36 +380,33 @@ where
384380
};
385381

386382
match action_request.action.as_str() {
387-
"retry" => {
388-
match queue.retry_job(job_uuid, chrono::Utc::now()).await {
389-
Ok(()) => {
390-
let response = ApiResponse::success(serde_json::json!({
391-
"message": format!("Job '{}' scheduled for retry", job_id)
392-
}));
393-
Ok(warp::reply::json(&response))
394-
}
395-
Err(e) => {
396-
let response = ApiResponse::<()>::error(format!("Failed to retry job: {}", e));
397-
Ok(warp::reply::json(&response))
398-
}
383+
"retry" => match queue.retry_job(job_uuid, chrono::Utc::now()).await {
384+
Ok(()) => {
385+
let response = ApiResponse::success(serde_json::json!({
386+
"message": format!("Job '{}' scheduled for retry", job_id)
387+
}));
388+
Ok(warp::reply::json(&response))
399389
}
400-
}
401-
"cancel" | "delete" => {
402-
match queue.delete_job(job_uuid).await {
403-
Ok(()) => {
404-
let response = ApiResponse::success(serde_json::json!({
405-
"message": format!("Job '{}' deleted", job_id)
406-
}));
407-
Ok(warp::reply::json(&response))
408-
}
409-
Err(e) => {
410-
let response = ApiResponse::<()>::error(format!("Failed to delete job: {}", e));
411-
Ok(warp::reply::json(&response))
412-
}
390+
Err(e) => {
391+
let response = ApiResponse::<()>::error(format!("Failed to retry job: {}", e));
392+
Ok(warp::reply::json(&response))
413393
}
414-
}
394+
},
395+
"cancel" | "delete" => match queue.delete_job(job_uuid).await {
396+
Ok(()) => {
397+
let response = ApiResponse::success(serde_json::json!({
398+
"message": format!("Job '{}' deleted", job_id)
399+
}));
400+
Ok(warp::reply::json(&response))
401+
}
402+
Err(e) => {
403+
let response = ApiResponse::<()>::error(format!("Failed to delete job: {}", e));
404+
Ok(warp::reply::json(&response))
405+
}
406+
},
415407
_ => {
416-
let response = ApiResponse::<()>::error(format!("Unknown action: {}", action_request.action));
408+
let response =
409+
ApiResponse::<()>::error(format!("Unknown action: {}", action_request.action));
417410
Ok(warp::reply::json(&response))
418411
}
419412
}
@@ -503,7 +496,7 @@ mod tests {
503496
"priority": "high",
504497
"max_attempts": 5
505498
}"#;
506-
499+
507500
let request: CreateJobRequest = serde_json::from_str(json).unwrap();
508501
assert_eq!(request.queue_name, "email");
509502
assert_eq!(request.priority, Some("high".to_string()));
@@ -525,9 +518,9 @@ mod tests {
525518
"action": "delete",
526519
"reason": "Cleanup old jobs"
527520
}"#;
528-
521+
529522
let request: BulkJobActionRequest = serde_json::from_str(json).unwrap();
530523
assert_eq!(request.job_ids.len(), 3);
531524
assert_eq!(request.action, "delete");
532525
}
533-
}
526+
}

hammerwork-web/src/api/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,15 @@ impl SortParams {
186186
}
187187

188188
/// Common error handling for API endpoints
189-
pub async fn handle_api_error(err: warp::Rejection) -> Result<impl warp::Reply, std::convert::Infallible> {
189+
pub async fn handle_api_error(
190+
err: warp::Rejection,
191+
) -> Result<impl warp::Reply, std::convert::Infallible> {
190192
let response = if err.is_not_found() {
191193
ApiResponse::<()>::error("Resource not found".to_string())
192-
} else if err.find::<warp::filters::body::BodyDeserializeError>().is_some() {
194+
} else if err
195+
.find::<warp::filters::body::BodyDeserializeError>()
196+
.is_some()
197+
{
193198
ApiResponse::<()>::error("Invalid request body".to_string())
194199
} else if err.find::<warp::reject::InvalidQuery>().is_some() {
195200
ApiResponse::<()>::error("Invalid query parameters".to_string())
@@ -199,8 +204,11 @@ pub async fn handle_api_error(err: warp::Rejection) -> Result<impl warp::Reply,
199204

200205
let status = if err.is_not_found() {
201206
warp::http::StatusCode::NOT_FOUND
202-
} else if err.find::<warp::filters::body::BodyDeserializeError>().is_some()
203-
|| err.find::<warp::reject::InvalidQuery>().is_some() {
207+
} else if err
208+
.find::<warp::filters::body::BodyDeserializeError>()
209+
.is_some()
210+
|| err.find::<warp::reject::InvalidQuery>().is_some()
211+
{
204212
warp::http::StatusCode::BAD_REQUEST
205213
} else {
206214
warp::http::StatusCode::INTERNAL_SERVER_ERROR
@@ -213,12 +221,14 @@ pub async fn handle_api_error(err: warp::Rejection) -> Result<impl warp::Reply,
213221
}
214222

215223
/// Extract pagination parameters from query string
216-
pub fn with_pagination() -> impl warp::Filter<Extract = (PaginationParams,), Error = warp::Rejection> + Clone {
224+
pub fn with_pagination()
225+
-> impl warp::Filter<Extract = (PaginationParams,), Error = warp::Rejection> + Clone {
217226
warp::query::<PaginationParams>()
218227
}
219228

220229
/// Extract filter parameters from query string
221-
pub fn with_filters() -> impl warp::Filter<Extract = (FilterParams,), Error = warp::Rejection> + Clone {
230+
pub fn with_filters()
231+
-> impl warp::Filter<Extract = (FilterParams,), Error = warp::Rejection> + Clone {
222232
warp::query::<FilterParams>()
223233
}
224234

@@ -273,7 +283,7 @@ mod tests {
273283
offset: None,
274284
};
275285
let meta = PaginationMeta::new(&params, 45);
276-
286+
277287
assert_eq!(meta.page, 2);
278288
assert_eq!(meta.limit, 10);
279289
assert_eq!(meta.total, 45);
@@ -303,4 +313,4 @@ mod tests {
303313
assert_eq!(field, "name");
304314
assert_eq!(direction, "ASC");
305315
}
306-
}
316+
}

0 commit comments

Comments
 (0)