Core.HTTP.Handlers (ServCore v0.3.0)

Copy Markdown View Source

Plain functions for handling HTTP requests.

These functions can be called directly from router definitions, giving forking developers full control over which routes to mount and how to wrap them (e.g. authentication, logging, rate limiting).

Summary

Functions

Handles POST /jobs — submits a job to the given queue.

Handles GET /jobs/:id — fetches a single job by ID.

Checks health of the given queues and returns a tuple of {status_code, body_map}.

Handles GET /jobs — lists jobs with optional filtering and pagination.

Handles POST /jobs/schedule — schedules a job for a future time.

Renders a JSON response with the given HTTP status code.

Aggregates stats across the given queues and returns a stats map.

Functions

create_job(conn, queue \\ JobQueue)

Handles POST /jobs — submits a job to the given queue.

get_job(conn, id, queue \\ JobQueue)

Handles GET /jobs/:id — fetches a single job by ID.

health_check(queues)

Checks health of the given queues and returns a tuple of {status_code, body_map}.

list_jobs(conn, queue \\ JobQueue)

Handles GET /jobs — lists jobs with optional filtering and pagination.

schedule_job(conn, queue \\ JobQueue)

Handles POST /jobs/schedule — schedules a job for a future time.

send_json(conn, status, body)

Renders a JSON response with the given HTTP status code.

stats_response(queues)

Aggregates stats across the given queues and returns a stats map.