solid_queue_mongoid provides Mongoid-based models that mirror the structure of SolidQueue's ActiveRecord models. This allows SolidQueue to work with MongoDB instead of PostgreSQL/MySQL/SQLite.
SolidQueue's models inherit from ActiveRecord::Base and use ActiveRecord-specific features throughout (transactions, locking, insert_all, etc.). An adapter pattern would be extremely complex and fragile.
Instead, we:
- Reimplement models using Mongoid that match SolidQueue's API surface
- Load before SolidQueue and prevent SolidQueue's AR models from loading
- Maintain API compatibility so business logic works unchanged
- Mirror structure so updates from SolidQueue can be easily ported
- Check SolidQueue's CHANGELOG
- For business logic changes in model methods → port to our models
- For new fields → add to our Mongoid field definitions
- For new indexes → add Mongoid index declarations
- For new models → create equivalent Mongoid model
- Database migrations (we use Mongoid schema)
- ActiveRecord-specific code (transactions, locking strategies)
- SQL-specific optimizations
Run SolidQueue's test suite against our Mongoid models to ensure API compatibility.
MongoDB transactions require replica sets. We fall back to non-transactional operation when not available.
FOR UPDATE SKIP LOCKED→ Not available in MongoDB- We use atomic operations (
$inc,findAndModify) instead
insert_all→ Individual inserts (MongoDB hasinsertManybut Mongoid doesn't expose it the same way)upsert_all→ Individual find_one_and_replace operations
- ActiveRecord uses
bigintIDs - Mongoid uses
BSON::ObjectId - This affects foreign key relationships
lib/solid_queue_mongoid/
models/
record.rb # Base model (replaces AR::Base)
job.rb # Job model
job/
executable.rb # Mirrors SolidQueue::Job::Executable
clearable.rb # Mirrors SolidQueue::Job::Clearable
...
execution.rb # Base execution
ready_execution.rb # Ready jobs
claimed_execution.rb # In-progress jobs
...
Each file mirrors its SolidQueue counterpart in app/models/solid_queue/.
| SolidQueue Version | solid_queue_mongoid Version | Status |
|---|---|---|
| 1.0.x - 1.3.x | 0.1.0 | Initial implementation |
When porting changes from SolidQueue:
- Reference the SolidQueue commit/PR
- Explain any deviations due to MongoDB differences
- Update this document if architectural changes are needed