Class: Resque::Worker
- Inherits:
-
Object
- Object
- Resque::Worker
- Defined in:
- lib/resque-multi-job-forks.rb
Instance Attribute Summary collapse
-
#jobs_per_fork ⇒ Object
Returns the value of attribute jobs_per_fork.
-
#jobs_processed ⇒ Object
readonly
Returns the value of attribute jobs_processed.
-
#seconds_per_fork ⇒ Object
Returns the value of attribute seconds_per_fork.
Instance Method Summary collapse
- #fork_hijacked? ⇒ Boolean
- #fork_job_limit ⇒ Object
- #fork_job_limit_reached? ⇒ Boolean
- #fork_job_limit_remaining ⇒ Object
- #hijack_fork ⇒ Object
- #minutes_per_fork ⇒ Object
- #perform_with_multi_job_forks(job = nil) ⇒ Object (also: #perform)
- #release_fork ⇒ Object
- #shutdown_with_multi_job_forks ⇒ Object (also: #shutdown?)
Instance Attribute Details
#jobs_per_fork ⇒ Object
Returns the value of attribute jobs_per_fork.
7 8 9 |
# File 'lib/resque-multi-job-forks.rb', line 7 def jobs_per_fork @jobs_per_fork end |
#jobs_processed ⇒ Object (readonly)
Returns the value of attribute jobs_processed.
8 9 10 |
# File 'lib/resque-multi-job-forks.rb', line 8 def jobs_processed @jobs_processed end |
#seconds_per_fork ⇒ Object
Returns the value of attribute seconds_per_fork.
6 7 8 |
# File 'lib/resque-multi-job-forks.rb', line 6 def seconds_per_fork @seconds_per_fork end |
Instance Method Details
#fork_hijacked? ⇒ Boolean
27 28 29 |
# File 'lib/resque-multi-job-forks.rb', line 27 def fork_hijacked? @release_fork_limit end |
#fork_job_limit ⇒ Object
49 50 51 |
# File 'lib/resque-multi-job-forks.rb', line 49 def fork_job_limit jobs_per_fork.nil? ? Time.now.to_i + seconds_per_fork : jobs_per_fork end |
#fork_job_limit_reached? ⇒ Boolean
53 54 55 |
# File 'lib/resque-multi-job-forks.rb', line 53 def fork_job_limit_reached? fork_job_limit_remaining <= 0 ? true : false end |
#fork_job_limit_remaining ⇒ Object
57 58 59 |
# File 'lib/resque-multi-job-forks.rb', line 57 def fork_job_limit_remaining jobs_per_fork.nil? ? @release_fork_limit - Time.now.to_i : jobs_per_fork - @jobs_processed end |
#hijack_fork ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/resque-multi-job-forks.rb', line 31 def hijack_fork log 'hijack fork.' @suppressed_fork_hooks = [Resque.after_fork, Resque.before_fork] Resque.after_fork = Resque.before_fork = nil @release_fork_limit = fork_job_limit @jobs_processed = 0 @cant_fork = true end |
#minutes_per_fork ⇒ Object
65 66 67 |
# File 'lib/resque-multi-job-forks.rb', line 65 def minutes_per_fork ENV['MINUTES_PER_FORK'].nil? ? 1 : ENV['MINUTES_PER_FORK'].to_i end |
#perform_with_multi_job_forks(job = nil) ⇒ Object Also known as: perform
11 12 13 14 15 |
# File 'lib/resque-multi-job-forks.rb', line 11 def perform_with_multi_job_forks(job = nil) perform_without_multi_job_forks(job) hijack_fork unless fork_hijacked? @jobs_processed += 1 end |
#release_fork ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/resque-multi-job-forks.rb', line 40 def release_fork log "jobs processed by child: #{jobs_processed}" run_hook :before_child_exit, self Resque.after_fork, Resque.before_fork = *@suppressed_fork_hooks @release_fork_limit = @jobs_processed = @cant_fork = nil log 'hijack over, counter terrorists win.' @shutdown = true unless $TESTING end |
#shutdown_with_multi_job_forks ⇒ Object Also known as: shutdown?
19 20 21 22 |
# File 'lib/resque-multi-job-forks.rb', line 19 def shutdown_with_multi_job_forks release_fork if fork_hijacked? && fork_job_limit_reached? shutdown_without_multi_job_forks end |