@@ -85,46 +85,41 @@ def redis_id
85
85
# changes you make will be permanent for the lifespan of the
86
86
# worker.
87
87
#
88
- # Call with a block to register a hook.
89
- # Call with no arguments to return all registered hooks .
88
+ # Call with a block to set the hook.
89
+ # Call with no arguments to return the hook .
90
90
def before_first_fork ( &block )
91
- block ? register_hook ( : before_first_fork, block ) : hooks ( : before_first_fork)
91
+ block ? ( @ before_first_fork = block ) : @ before_first_fork
92
92
end
93
93
94
- # Register a before_first_fork proc.
95
- def before_first_fork = ( block )
96
- register_hook ( :before_first_fork , block )
97
- end
94
+ # Set a proc that will be called in the parent process before the
95
+ # worker forks for the first time.
96
+ attr_writer :before_first_fork
98
97
99
98
# The `before_fork` hook will be run in the **parent** process
100
99
# before every job, so be careful- any changes you make will be
101
100
# permanent for the lifespan of the worker.
102
101
#
103
- # Call with a block to register a hook.
104
- # Call with no arguments to return all registered hooks .
102
+ # Call with a block to set the hook.
103
+ # Call with no arguments to return the hook .
105
104
def before_fork ( &block )
106
- block ? register_hook ( : before_fork, block ) : hooks ( : before_fork)
105
+ block ? ( @ before_fork = block ) : @ before_fork
107
106
end
108
107
109
- # Register a before_fork proc.
110
- def before_fork = ( block )
111
- register_hook ( :before_fork , block )
112
- end
108
+ # Set the before_fork proc.
109
+ attr_writer :before_fork
113
110
114
111
# The `after_fork` hook will be run in the child process and is passed
115
112
# the current job. Any changes you make, therefore, will only live as
116
113
# long as the job currently being processed.
117
114
#
118
- # Call with a block to register a hook.
119
- # Call with no arguments to return all registered hooks .
115
+ # Call with a block to set the hook.
116
+ # Call with no arguments to return the hook .
120
117
def after_fork ( &block )
121
- block ? register_hook ( : after_fork, block ) : hooks ( : after_fork)
118
+ block ? ( @ after_fork = block ) : @ after_fork
122
119
end
123
120
124
- # Register an after_fork proc.
125
- def after_fork = ( block )
126
- register_hook ( :after_fork , block )
127
- end
121
+ # Set the after_fork proc.
122
+ attr_writer :after_fork
128
123
129
124
# The `before_pause` hook will be run in the parent process before the
130
125
# worker has paused processing (via #pause_processing or SIGUSR2).
@@ -408,29 +403,5 @@ def keys
408
403
key . sub ( "#{ redis . namespace } :" , '' )
409
404
end
410
405
end
411
-
412
- private
413
-
414
- # Register a new proc as a hook. If the block is nil this is the
415
- # equivalent of removing all hooks of the given name.
416
- #
417
- # `name` is the hook that the block should be registered with.
418
- def register_hook ( name , block )
419
- return clear_hooks ( name ) if block . nil?
420
-
421
- @hooks ||= { }
422
- @hooks [ name ] ||= [ ]
423
- @hooks [ name ] << block
424
- end
425
-
426
- # Clear all hooks given a hook name.
427
- def clear_hooks ( name )
428
- @hooks && @hooks [ name ] = [ ]
429
- end
430
-
431
- # Retrieve all hooks of a given name.
432
- def hooks ( name )
433
- ( @hooks && @hooks [ name ] ) || [ ]
434
- end
435
406
end
436
407
0 commit comments