You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11
Original file line number
Diff line number
Diff line change
@@ -379,6 +379,9 @@ And into two different points in the worker's, dispatcher's and scheduler's life
379
379
- `(worker|dispatcher|scheduler)_start`: after the worker/dispatcher/scheduler has finished booting and right before it starts the polling loop or loading the recurring schedule.
380
380
- `(worker|dispatcher|scheduler)_stop`: after receiving a signal (`TERM`, `INT` or `QUIT`) and right before starting graceful or immediate shutdown (which is just `exit!`).
381
381
382
+
The hooks for workers will have the worker instance yielded to the block so that you may read its configuration
383
+
for logging or other metrics reporting purposes.
384
+
382
385
You can use the following methods with a block to do this:
383
386
```ruby
384
387
SolidQueue.on_start
@@ -398,6 +401,14 @@ For example:
398
401
```ruby
399
402
SolidQueue.on_start { start_metrics_server }
400
403
SolidQueue.on_stop { stop_metrics_server }
404
+
405
+
SolidQueue.on_worker_start do |worker|
406
+
Rails.logger.info "Worker #{worker.worker_id} started with queues: #{worker.queues.join(',')}"
407
+
end
408
+
409
+
SolidQueue.on_worker_stop do |worker|
410
+
Rails.logger.info "Worker #{worker.worker_id} stopped with queues: #{worker.queues.join(',')}"
411
+
end
401
412
```
402
413
403
414
These can be called several times to add multiple hooks, but it needs to happen before Solid Queue is started. An initializer would be a good place to do this.
0 commit comments