Class: Wurk::Web::BatchStatus
- Inherits:
-
Object
- Object
- Wurk::Web::BatchStatus
- Defined in:
- lib/wurk/web/batch_status.rb
Overview
Lightweight Rack middleware for batch-progress polling without mounting the full dashboard. Drop into a rack stack and app JS can drive progress bars off plain JSON:
# config.ru
use Sidekiq::Pro::BatchStatus
run Rails.application
‘GET /batch_status/<bid>.json` → `Wurk::Batch::Status#data` JSON (bid, total, pending, failures, complete, created_at, description, …). Unknown/expired bid → 404. Every other request passes straight through.
Spec: docs/target/sidekiq-pro.md §10.3.
Constant Summary collapse
- ROUTE =
%r{\A/batch_status/(?<bid>[^/]+)\.json\z}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ BatchStatus
constructor
A new instance of BatchStatus.
Constructor Details
#initialize(app) ⇒ BatchStatus
Returns a new instance of BatchStatus.
23 24 25 |
# File 'lib/wurk/web/batch_status.rb', line 23 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wurk/web/batch_status.rb', line 27 def call(env) match = env['REQUEST_METHOD'] == 'GET' && ROUTE.match(env['PATH_INFO']) return @app.call(env) unless match status = Wurk::Batch::Status.new(match[:bid]) status.exists? ? json(200, status.data) : json(404, { 'error' => 'not_found' }) end |