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

Optimize Job Processing Endpoint to Use Async Queue #202

Open
Mohiiit opened this issue Jan 6, 2025 · 0 comments
Open

Optimize Job Processing Endpoint to Use Async Queue #202

Mohiiit opened this issue Jan 6, 2025 · 0 comments

Comments

@Mohiiit
Copy link
Contributor

Mohiiit commented Jan 6, 2025

Description:

The current implementation of the handle_process_job_request endpoint directly calls the process_job function, which might involve long-running operations. Since this endpoint is part of a REST API, prolonged processing times can lead to timeouts, degraded performance, and a poor user experience.

Current Code Snippet:

#[instrument(skip(config), fields(job_id = %id))]
async fn handle_process_job_request(
    Path(JobId { id }): Path<JobId>,
    State(config): State<Arc<Config>>,
) -> JobRouteResult {
    let job_id = Uuid::parse_str(&id).map_err(|_| JobRouteError::InvalidId(id.clone()))?;

    match process_job(job_id, config).await {
        Ok(_) => {
            info!("Job processed successfully");
            ORCHESTRATOR_METRICS.successful_job_operations.add(1.0, &[KeyValue::new("operation_type", "process_job")]);
            Ok(Json(ApiResponse::success()).into_response())
        }
        Err(e) => {
            error!(error = %e, "Failed to process job");
            ORCHESTRATOR_METRICS.failed_job_operations.add(1.0, &[KeyValue::new("operation_type", "process_job")]);
            Err(JobRouteError::ProcessingError(e.to_string()))
        }
    }
}

Problem Statement:

  • Long-running operations in an HTTP endpoint can result in timeouts.
  • The API should respond quickly after successfully adding the job to a queue.

Proposed Solution:

  • Instead of directly processing the job in the HTTP handler, add the job to an asynchronous task queue.
  • Return a 200 OK response immediately after successfully adding the job to the queue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant