Background Jobs & Queue
Relevant source files
The following files were used as context for generating this wiki page:
Background jobs in RateGuru are utilized to handle asynchronous tasks that should not block the main application thread, ensuring a responsive user experience. The system is built on Laravel's queue architecture, directing technical helpers and background processing into dedicated classes.
The scope of background work includes tasks such as image processing, notification dispatching, and high-frequency counter recalculations. By offloading these operations, the application maintains performance during intensive actions like post creation or mass data seeding.
Architecture & Configuration
RateGuru follows a standard Laravel queue architecture where business logic remains in Actions, while technical background work is encapsulated within Jobs.
Queue Configuration
The project is configured to be "SQLite first," and the production environment documentation specifies that Redis is not strictly required for queue management. The system supports multiple drivers, with sync often used for simple setups or testing environments.
Sources: AGENTS.md:12, AGENTS.md:27, tests/Feature/Docs/DeploymentDocsTest.php:65, tests/Feature/Docs/DeploymentDocsTest.php:69
Component Relationship
The following diagram illustrates how different application layers interact with the background job system:
Visual representation of the separation between Livewire components, business Actions, and Background Jobs.
Sources: AGENTS.md:23-27, tests/Feature/Routes/FeedRouteTest.php:100-104
Key Job Implementations
Image Processing
One of the primary uses of background jobs is the processing of uploaded images. When a user uploads a post, the image is initially stored locally before being processed (e.g., thumbnail generation, resizing).
| Job Component | Purpose | Context |
|---|---|---|
ProcessUploadedImageJob | Handles resizing and optimization of user-uploaded media. | Post Upload |
NotifyFollowersAboutNewPostJob | Dispatches notifications to users following an author. | Post Publication |
Sources: AGENTS.md:54-55, resources/views/livewire/feed/upload-post-form.blade.php:83-110
Notification System
The system utilizes background jobs to notify followers when a new post is published. This ensures that the user who published the post does not experience latency while the system iterates through potentially hundreds of followers to send alerts.
Sequence of asynchronous notification dispatching after a post is published.
Sources: AGENTS.md:27, lang/en/ui.php:144-149
Operational Management
Deployment and Maintenance
The queue system requires active workers in a production environment. RateGuru's deployment checklist includes specific commands and precautions for managing these processes.
- Worker Command:
php artisan queue:workis the standard command for processing jobs. - Restarts: When code is updated,
php artisan queue:restartmust be called to ensure workers use the latest application state. - Environment: The
QUEUE_CONNECTIONenvironment variable determines the driver (e.g.,database,sync,redis).
Sources: tests/Feature/Docs/DeploymentDocsTest.php:68-71
Data Seeding and Counters
During bulk operations, such as running the DemoFillSeeder, background-style logic is used to recalculate counters for comments and post scores. This prevents database deadlocks and maintains data integrity during high-volume inserts.
Sources: database/seeders/DemoFillSeeder.php:570-585
Summary
Background jobs and queues in RateGuru are essential for maintaining the "thin controller" architecture and ensuring the application remains responsive. By utilizing Laravel's built-in queueing capabilities—optimized for SQLite-first environments—the project efficiently handles image processing and social notifications without impacting the primary request-response cycle.