DB-backed Queue
A database queue table combined with a MySQL event can process background jobs without an external queue system — useful for small-scale needs.
A database queue table combined with a MySQL event can process background jobs without an external queue system — useful for small-scale needs.
DELIMITER //
CREATE EVENT process_job_queue
ON SCHEDULE EVERY 1 MINUTE
DO
BEGIN
DECLARE done INT DEFAULT 0;
-- Pick and lock next pending job
UPDATE job_queue SET status = "processing", started_at = NOW(), worker = CONNECTION_ID()
WHERE status = "pending" ORDER BY created_at LIMIT 1;
-- Log processing attempt
IF ROW_COUNT() > 0 THEN
INSERT INTO event_audit (event_name, run_at) VALUES ("queue_processor", NOW());
END IF;
END//
DELIMITER ;
For high-throughput queues, use Redis (Laravel), SQS, or RabbitMQ instead of a DB-backed queue.