Sidekiq Web UI Extension
Relevant source files
The following files were used as context for generating this wiki page:
The Sidekiq Web UI Extension provides a graphical interface for managing unique job locks within the Sidekiq dashboard. It enables developers and operators to browse, filter, and manually delete locks that are currently held in Redis. This is particularly useful for troubleshooting stuck jobs or clearing stale locks that were not released due to process crashes or logic errors.
Sources: README.md:144-148, lib/sidekiq_unique_jobs/web/helpers.rb:10-14
Architecture and Integration
The extension integrates directly into the Sidekiq::Web application. It introduces a dedicated Locks tab and a set of endpoints to interact with the underlying SidekiqUniqueJobs::Digests collection.
The extension uses a set of specific view helpers to handle parameter sanitization, time formatting, and lock argument display.
Sources: lib/sidekiq_unique_jobs/web/helpers.rb:10-20, README.md:144-150
API Endpoints and Routing
The extension defines several routes for managing the lifecycle of unique locks. These endpoints allow for both granular control (deleting specific job IDs within a lock) and bulk operations.
| Endpoint | Method | Description |
|---|---|---|
/locks | GET | Displays a paginated list of all current unique digests. |
/locks/:digest | GET | Displays detailed information for a specific lock digest. |
/locks/:digest/delete | GET | Deletes the entire lock associated with the provided digest. |
/locks/:digest/jobs/:jid/delete | GET | Removes a specific Job ID (JID) from a lock without deleting the entire digest. |
/locks/delete_all | GET | Clears all unique job locks from the Redis store. |
Sources: spec/sidekiq_unique_jobs/web_spec.rb:42-108
View Helpers and Templates
The SidekiqUniqueJobs::Web::Helpers module provides the logic necessary to render lock data safely and accurately.
Data Sanitization and Formatting
The extension ensures that only specific parameters are passed through the UI to prevent injection or invalid queries. It also handles the truncation of large job arguments to maintain UI performance.
- SAFE_CPARAMS: A whitelist of allowed parameters:
filter,count,cursor,prev_cursor,poll,direction. - display_lock_args: Truncates job arguments (defaulting to 2000 characters) and escapes HTML to prevent XSS.
- _safe_relative_time: Converts timestamps (Integer, Float, or String) into HTML
<time>tags with ISO8601 attributes for consistent browser rendering.
Sources: lib/sidekiq_unique_jobs/web/helpers.rb:21-25, lib/sidekiq_unique_jobs/web/helpers.rb:69-84, lib/sidekiq_unique_jobs/web/helpers.rb:112-123
Template Management
Templates are stored within the gem's internal file structure and loaded dynamically.
Lock Interaction Logic
When interacting with the Web UI, the system performs actions against the SidekiqUniqueJobs::Digests and SidekiqUniqueJobs::Lock classes.
- Deletion Flow: When a user triggers a delete via the UI, the system identifies the digest. For individual job removal, it targets the specific JID within that digest's locked set.
- Redirection: After an action (like
delete_all), the helperredirect_toensures the user is returned to the relative root of the Sidekiq Web interface, maintaining compatibility with apps mounted at sub-paths.
Sources: lib/sidekiq_unique_jobs/web/helpers.rb:93-100, spec/sidekiq_unique_jobs/web_spec.rb:71-80
Conclusion
The Sidekiq Web UI Extension serves as the primary observability and administrative tool for sidekiq-unique-jobs. By providing a clear mapping of Redis-backed digests to human-readable job information, it allows for effective management of the lock lifecycle directly from the Sidekiq dashboard.