Skip to main content

Crate asyncq_actix

Crate asyncq_actix 

Source
Expand description

Actix-web integration for asyncq — admin REST endpoints with Prometheus metrics.

§Setup

Mount the admin scope in your actix-web application:

use asyncq::{Queue, backends::InMemoryBackend};
use asyncq_actix::admin;
use actix_web::{web, App, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let queue = Queue::new(InMemoryBackend::new());

    HttpServer::new(move || {
        App::new()
            .service(web::scope("/admin").configure(admin(queue.clone())))
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

For live Prometheus metrics, use admin_with_queues:

use asyncq_actix::admin_with_queues;
App::new()
    .service(
        web::scope("/admin")
            .configure(admin_with_queues(queue, vec!["emails".into(), "payments".into()]))
    );

§Endpoints

MethodPathDescription
GET/admin/queues/{name}Stats for a queue
GET/admin/queues/{name}/dlqDead-letter queue (paginated)
POST/admin/queues/{name}/dlq/retry-allRequeue all dead jobs
DELETE/admin/queues/{name}/dlq/{id}Retry one dead job by ID
GET/admin/metricsPrometheus text metrics

Functions§

admin
Returns an actix-web configurator that mounts admin endpoints. Apply to a scope: web::scope("/admin").configure(admin(queue)).
admin_with_queues
Returns an actix-web configurator with live Prometheus metrics for the given queues.