Socket
Book a DemoInstallSign in
Socket

github.com/PAFFx/job-poll-queue

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/PAFFx/job-poll-queue

v0.0.0-20250505104750-e538e2cd3d5c
Source
Go
Version published
Created
Source

Job Queue API

A lightweight job processing queue with HTTP and gRPC APIs.

Features

  • Synchronous job processing
  • RESTful API using Gofiber framework
  • gRPC API for efficient worker communication
  • Persistent storage
  • Thread-safe operations

Installation

git clone https://github.com/PAFFx/job-poll-queue.git
cd job-poll-queue
go mod download
go build

HTTP API Endpoints

Client Endpoints

Submit a job (synchronous)

POST /api/submit

Request: Send any JSON payload in the body
Response: Returns the worker's processed result

{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "payload": {/* Worker's response payload */},
  "created_at": "2023-06-01T12:34:56Z",
  "completed_at": "2023-06-01T12:34:58Z"
}

Worker Endpoints

Poll for a job

GET /api/worker/poll

Response (when job available):

{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "payload": {/* Original job payload */},
  "headers": {/* Original request headers */}
}

Complete a job

POST /api/worker/complete/:id

Request: Send any payload in the body (can be JSON, text, or any format)
Response:

{
  "message": "Job completed",
  "job_id": "550e8400-e29b-41d4-a716-446655440000"
}

Admin Endpoints

Get queue stats

GET /api/admin/stats

Clear the queue

DELETE /api/admin/clear

Get next job (admin only)

GET /api/admin/next

Health check

GET /health

gRPC API

Worker service is also available via gRPC on port 50051 (configurable).

Methods

  • RequestJob: Retrieves the next available job
  • CompleteJob: Submits results for a processed job

Testing with grpcurl

# List available services
grpcurl -plaintext localhost:50051 list

# Request a job
grpcurl -plaintext -d '{}' localhost:50051 worker.WorkerService/RequestJob

# Complete a job
grpcurl -plaintext -d '{"job_id":"JOB_ID","payload":"result"}' \
  localhost:50051 worker.WorkerService/CompleteJob

Architecture

The system now supports dual communication methods:

  • HTTP API: Traditional RESTful endpoints for client, worker, and admin operations
  • gRPC API: Efficient binary protocol for worker communication

The core components remain:

  • Submit API: Handles job submissions from clients
  • Worker API: Allows workers to poll for jobs and submit results (via HTTP or gRPC)
  • Job Status Manager: Tracks job state throughout its lifecycle

Jobs submitted by clients are held in a synchronous request until a worker processes the job and returns a result, which is then returned to the client.

Project Structure

job-poll-queue/
├── api/              # API implementations
│   ├── http/         # HTTP API endpoints
│   │   ├── admin/    # Admin HTTP endpoints  
│   │   ├── submit/   # Client submission endpoints
│   │   ├── worker/   # Worker HTTP endpoints
│   │   └── server.go # HTTP server and routes
│   └── grpc/         # gRPC API endpoints
│       ├── worker/   # Worker gRPC service
│       └── server.go # gRPC server
├── proto/            # Protocol buffer definitions
│   └── worker/       # Worker service proto definitions
├── queue/            # Core queue implementation
│   ├── jobstatus.go  # Job status tracking
│   ├── queue.go      # Main queue functionality
│   └── storage.go    # Persistence layer
├── config/           # Configuration
│   └── env.go        # Environment variables
└── main.go           # Application entry point (runs both servers)

License

MIT

FAQs

Package last updated on 05 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.