workless 1.2.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 247a947751bcae149a8352caca4aec7e96bd13e8
4
- data.tar.gz: 34249b4154b3537e0ad4aa6203b66edebb6a9240
3
+ metadata.gz: 473c0f1c1861f33cc1871d549c90263baeb7c793
4
+ data.tar.gz: 2473df42e988787e5f231795e5066ef8d44d245f
5
5
  SHA512:
6
- metadata.gz: 2c7dd90c1ce19d602d5f0f27b94d7929b3b9f5495bdd61a2c30eb5f9dd5f5efd715883479a61d186d80051fdaa7a34a33f5dc8cbc61390d257aa5eec53880dd6
7
- data.tar.gz: 1c1bc50df460cdd7274552deb1be04022b3d7b67a9677ceabbea6c32bca8c47364b72a562711ad41ba279d18e35ba7e9511b93c1491ac5c7759b5cece381acf0
6
+ metadata.gz: 01d825fe3475a68120e35026736d51d86c0f5174c631b0d4e7c65e012a5897de29b8b86232c9fd992f9d8b4d6de31fc61367bec424817606e1aca70e108b3d41
7
+ data.tar.gz: 92797b2ad0176b0d2e6ef465b31db5357994b475f7064fa95ebb0cb7fa23efa1e7c28211146331651db5b306e14b9b1617c008027a0d6c032376481d1f0c9650
data/README.md CHANGED
@@ -9,8 +9,19 @@ It is designed to be used when you're using Heroku as a host and have the need t
9
9
 
10
10
  By adding the gem to your project and configuring our Heroku app with some config variables workless should do the rest.
11
11
 
12
+ :warning: **[The Legacy API will be sunset on April 15th, 2017](https://devcenter.heroku.com/changelog-items/862)** :warning:
13
+ Please upgrade to version 2.0.0 as soon as you can. Version 2.0.0 is released on March 1st, 2017.
14
+
15
+ ## Heroku Stack Heroku-16 update
16
+ Version 2.2.0 changed the config for setting the Heroku API key. This will now reside in WORKLESS_API_KEY. Please change this key in your Heroku setup when upgrading this gem!
17
+
12
18
  ## Updates
13
19
 
20
+ * Version 2.2.0 Revitalized by @davidakachaos through his workless_revived project, now merged for a 2.2.0 release.
21
+ * Version 1.3.0 DROPS SUPPORT FOR OLDER RUBY AND RAILS VERSIONS!
22
+ * Version 1.2.5 Added middleware to check on delayed jobs, fixed Rails 5 support
23
+ * Version 1.2.4 drops support for older versions!
24
+ * Version 1.2.3 replaces multiple commit callback with two callbacks for compatibility by @lostboy
14
25
  * Version 1.2.2 includes after_commit fix by @collectiveip
15
26
  * Version 1.2.1 includes support for Rails 4 & DJ 4 by @florentmorin
16
27
  * Version 1.2.0 includes new support for Sequel by @davidakachaos
@@ -22,45 +33,39 @@ By adding the gem to your project and configuring our Heroku app with some confi
22
33
 
23
34
  ## Compatibility
24
35
 
25
- Workless should work correctly with Rubies 1.8.7, ree, 1.9.2 and 1.9.3. It is compatible with Delayed Job since version 2.0.7 up to the latest version 3.0.1, the table below shows tested compatibility with ruby, rails and delayed_job
36
+ Workless should work correctly with Rubies 2.0.0 and up. It is compatible with Delayed Job since version 2.0.7 up to the latest version 4.1.2, the table below shows tested compatibility with ruby, rails and delayed_job
26
37
 
27
38
  Ruby | Rails | Delayed Job
28
39
  ---------- | ------ | -----
29
- 1.8.7-ree | 2.1.14 | 2.0.7
30
- 1.9.2 | 3.2 | 2.1.4
31
- 1.9.2 | 3.2 | 3.0.1
40
+ 2.2.5 | 4.2 | 2.1.4
41
+ 2.3.1 | 5.0 | 4.1.2
42
+ 2.4.1 | 5.1 | 4.1.3
32
43
 
33
44
  ## Installation
34
45
 
35
- Add the workless gem and the delayed_job gem to your project Gemfile and update your bundle. Its is recommended to specify the gem version for delayed_job especially if you are using rails 2.3.x which doesn't work with the latest delayed_job
36
-
37
- ### For rails 2.3.x the latest compatible delayed_job is 2.0.7
38
-
39
- <pre>
40
- gem "delayed_job", "2.0.7"
41
- gem "workless", "~> 1.1.3"
42
- </pre>
46
+ Add the workless gem and the delayed_job gem to your project Gemfile and update your bundle. Its is recommended to specify the gem version for delayed_job
43
47
 
44
- ### For rails 3.x with delayed_job 2.1.x
48
+ ### For rails 4.x with latest delayed_job 3.x using active record
45
49
 
46
50
  <pre>
47
- gem "delayed_job", "~> 2.1.4"
48
- gem "workless", "~> 1.1.3"
51
+ gem "delayed_job_active_record"
52
+ gem "workless", "~> 2.2.0"
49
53
  </pre>
50
54
 
51
- ### For rails 3.x with latest delayed_job 3.x using active record
55
+ ### For rails 5.x with latest delayed_job 3.x using active record
52
56
 
53
57
  <pre>
54
58
  gem "delayed_job_active_record"
55
- gem "workless", "~> 1.1.3"
59
+ gem "workless", "~> 2.0.0"
56
60
  </pre>
57
61
 
58
- If you don't specify delayed_job in your Gemfile workless will bring it in, most likely the latest version (3.0.1)
62
+
63
+ If you don't specify delayed_job in your Gemfile workless will bring it in, most likely the latest version (4.1.2)
59
64
 
60
65
  Add your Heroku app name / [API key](https://devcenter.heroku.com/articles/authentication) as config vars to your Heroku instance.
61
66
 
62
67
  <pre>
63
- heroku config:add HEROKU_API_KEY=yourapikey APP_NAME=yourherokuappname
68
+ heroku config:add WORKLESS_API_KEY=yourapikey APP_NAME=yourherokuappname
64
69
  </pre>
65
70
 
66
71
  ## Failing Jobs
@@ -72,7 +77,7 @@ In the case of failed jobs Workless will only shut down the dj worker if all att
72
77
  Workless can be disabled by using the null scaler that will ignore the workers requests to scale up and down. In an environment file add this in the config block:
73
78
 
74
79
  <pre>
75
- config.after_initialize do
80
+ config.after_initialize do
76
81
  Delayed::Job.scaler = :null
77
82
  end
78
83
  </pre>
@@ -81,11 +86,11 @@ There are three other scalers included. Note that if you are running on the Aspe
81
86
 
82
87
  <pre>
83
88
  Delayed::Job.scaler = :heroku
84
- Delayed::Job.scaler = :heroku_cedar
89
+ Delayed::Job.scaler = :heroku
85
90
  Delayed::Job.scaler = :local
86
91
  </pre>
87
92
 
88
- The local scaler uses @adamwiggins rush library http://github.com/adamwiggins/rush to start and stop workers on a local machine. The local scaler also relies on script/delayed_job (which in turn requires the daemon gem). If you have been using foreman to run your workers, go back and see the delayed_job [setup instructions](https://github.com/collectiveidea/delayed_job/blob/master/README.md).
93
+ The local scaler uses @adamwiggins rush library http://github.com/adamwiggins/rush to start and stop workers on a local machine. The local scaler also relies on script/delayed_job (which in turn requires the daemon gem). If you have been using foreman to run your workers, go back and see the delayed_job [setup instructions](https://github.com/collectiveidea/delayed_job/blob/master/README.md).
89
94
 
90
95
  The heroku scaler works on the Aspen and Bamboo stacks while the heroku_cedar scaler only works on the new Cedar stack.
91
96
 
@@ -109,7 +114,7 @@ In this example, it will scale up to a maximum of 10 workers, firing up 1 worker
109
114
  - A `destroy` callback stops the worker.
110
115
 
111
116
  ## Note on Patches/Pull Requests
112
-
117
+
113
118
  * Please fork the project.
114
119
  * Make your feature addition or bug fix.
115
120
  * Commit, do not mess with rakefile, version, or history.
@@ -118,4 +123,8 @@ In this example, it will scale up to a maximum of 10 workers, firing up 1 worker
118
123
 
119
124
  ## Copyright
120
125
 
121
- Copyright (c) 2010 lostboy. See LICENSE for details.
126
+ Copyright (c) 2010 lostboy.
127
+ Copyright (c) 2016 davidakachaos.
128
+ Copyright (c) 2017 lostboy && davidakachaos.
129
+
130
+ See LICENSE for details.
@@ -1,4 +1,6 @@
1
- require "heroku-api"
2
- require File.dirname(__FILE__) + "/workless/scalers/base"
3
- require File.dirname(__FILE__) + "/workless/scaler"
4
- require File.dirname(__FILE__) + "/workless/railtie" if defined?(Rails::Railtie)
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/workless/scalers/base'
4
+ require File.dirname(__FILE__) + '/workless/scaler'
5
+ require File.dirname(__FILE__) + '/workless/middleware/workless_checker' if defined?(Rails::Railtie)
6
+ require File.dirname(__FILE__) + '/workless/railtie' if defined?(Rails::Railtie)
@@ -1,4 +1,6 @@
1
- Delayed::Worker.max_attempts = 3
1
+ # frozen_string_literal: true
2
+
3
+ Delayed::Worker.max_attempts ||= 3
2
4
  Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job)
3
5
  Delayed::Backend::Mongoid::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::Mongoid::Job)
4
6
  Delayed::Backend::MongoMapper::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::MongoMapper::Job)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class WorklessChecker
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ status, headers, response = @app.call(env)
10
+ return [status, headers, response] if file?(headers) || empty?(response)
11
+
12
+ Delayed::Job.scaler.up unless Delayed::Job.scaler.jobs.empty?
13
+
14
+ [status, headers, response]
15
+ end
16
+
17
+ # fix issue if response's body is a Proc
18
+ def empty?(response)
19
+ # response may be ["Not Found"], ["Move Permanently"], etc.
20
+ (response.is_a?(Array) && response.size <= 1) ||
21
+ !response.respond_to?(:body) ||
22
+ !response.body.respond_to?(:empty?) ||
23
+ response.body.empty?
24
+ end
25
+
26
+ # if send file?
27
+ def file?(headers)
28
+ headers['Content-Transfer-Encoding'] == 'binary'
29
+ end
30
+ end
@@ -3,8 +3,9 @@ require 'delayed_job'
3
3
 
4
4
  module Delayed
5
5
  class Railtie < Rails::Railtie
6
- initializer :after_initialize do
6
+ initializer :after_initialize do |config|
7
7
  require 'workless/initialize'
8
+ config.middleware.use WorklessChecker
8
9
  end
9
10
  end
10
11
  end
@@ -1,20 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module Workless
3
5
  module Scaler
4
-
5
- autoload :Heroku, "workless/scalers/heroku"
6
- autoload :HerokuCedar, "workless/scalers/heroku_cedar"
7
- autoload :Local, "workless/scalers/local"
8
- autoload :Null, "workless/scalers/null"
6
+ autoload :Heroku, 'workless/scalers/heroku'
7
+ autoload :Local, 'workless/scalers/local'
8
+ autoload :Null, 'workless/scalers/null'
9
9
 
10
10
  def self.included(base)
11
11
  base.send :extend, ClassMethods
12
12
  if base.to_s =~ /ActiveRecord/
13
13
  base.class_eval do
14
- after_commit "self.class.scaler.down", :on => :update, :if => Proc.new {|r| !r.failed_at.nil? }
15
- after_commit "self.class.scaler.down", :on => :destroy, :if => Proc.new {|r| r.destroyed? or !r.failed_at.nil? }
16
- after_commit "self.class.scaler.up", :on => :create
17
- end
14
+ after_commit(on: :update, if: proc { |r| !r.failed_at.nil? }) do
15
+ self.class.scaler.down
16
+ end
17
+ after_commit(on: :destroy, if: proc { |r| r.destroyed? || !r.failed_at.nil? }) do
18
+ self.class.scaler.down
19
+ end
20
+ after_commit(on: :create) do
21
+ self.class.scaler.up
22
+ end
23
+ end
18
24
  elsif base.to_s =~ /Sequel/
19
25
  base.send(:define_method, 'after_destroy') do
20
26
  super
@@ -30,19 +36,19 @@ module Delayed
30
36
  end
31
37
  else
32
38
  base.class_eval do
33
- after_destroy "self.class.scaler.down"
34
- after_create "self.class.scaler.up"
35
- after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? }
39
+ after_destroy 'self.class.scaler.down'
40
+ after_create 'self.class.scaler.up'
41
+ after_update 'self.class.scaler.down', unless: proc { |r| r.failed_at.nil? }
36
42
  end
37
43
  end
38
44
  end
39
45
 
40
46
  module ClassMethods
41
47
  def scaler
42
- @scaler ||= if ENV.include?("HEROKU_API_KEY")
43
- Scaler::HerokuCedar
44
- else
45
- Scaler::Local
48
+ @scaler ||= if ENV.include?('WORKLESS_API_KEY')
49
+ Scaler::Heroku
50
+ else
51
+ Scaler::Local
46
52
  end
47
53
  end
48
54
 
@@ -50,8 +56,6 @@ module Delayed
50
56
  @scaler = "Delayed::Workless::Scaler::#{scaler.to_s.camelize}".constantize
51
57
  end
52
58
  end
53
-
54
59
  end
55
-
56
60
  end
57
61
  end
@@ -1,27 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delayed_job'
2
4
 
3
5
  module Delayed
4
6
  module Workless
5
7
  module Scaler
6
-
7
8
  class Base
8
9
  def self.jobs
9
- if Rails.version >= "3.0.0"
10
- Delayed::Job.where(:failed_at => nil)
11
- else
12
- Delayed::Job.all(:conditions => { :failed_at => nil })
13
- end
10
+ Delayed::Job.where(failed_at: nil)
14
11
  end
15
12
  end
16
13
 
17
14
  module HerokuClient
18
-
19
15
  def client
20
- @client ||= ::Heroku::API.new(:api_key => ENV['HEROKU_API_KEY'])
16
+ @client ||= ::PlatformAPI.connect(ENV['WORKLESS_API_KEY'])
21
17
  end
22
-
23
18
  end
24
-
25
19
  end
26
20
  end
27
21
  end
@@ -1,27 +1,55 @@
1
- require 'heroku-api'
1
+ # frozen_string_literal: true
2
+
3
+ require 'platform-api'
2
4
 
3
5
  module Delayed
4
6
  module Workless
5
7
  module Scaler
6
-
7
8
  class Heroku < Base
8
-
9
9
  extend Delayed::Workless::Scaler::HerokuClient
10
10
 
11
11
  def self.up
12
- client.put_workers(ENV['APP_NAME'], 1) if self.workers == 0
12
+ return unless workers_needed > min_workers && workers < workers_needed
13
+ updates = { "quantity": workers_needed }
14
+ client.formation.update(ENV['APP_NAME'], 'worker', updates)
13
15
  end
14
16
 
15
17
  def self.down
16
- client.put_workers(ENV['APP_NAME'], 0) unless self.jobs.count > 0 or self.workers == 0
18
+ return if workers == workers_needed
19
+ updates = { "quantity": workers_needed }
20
+ client.formation.update(ENV['APP_NAME'], 'worker', updates)
17
21
  end
18
22
 
19
23
  def self.workers
20
- client.get_ps(ENV['APP_NAME']).body.count { |p| p["process"] =~ /worker\.\d?/ }
24
+ client.formation.info(ENV['APP_NAME'], 'worker')['quantity'].to_i
21
25
  end
22
26
 
23
- end
27
+ # Returns the number of workers needed based on the current number of pending jobs and the settings defined by:
28
+ #
29
+ # ENV['WORKLESS_WORKERS_RATIO']
30
+ # ENV['WORKLESS_MAX_WORKERS']
31
+ # ENV['WORKLESS_MIN_WORKERS']
32
+ #
33
+ def self.workers_needed
34
+ [[(jobs.count.to_f / workers_ratio).ceil, max_workers].min, min_workers].max
35
+ end
24
36
 
37
+ def self.workers_ratio
38
+ if ENV['WORKLESS_WORKERS_RATIO'].present? && (ENV['WORKLESS_WORKERS_RATIO'].to_i != 0)
39
+ ENV['WORKLESS_WORKERS_RATIO'].to_i
40
+ else
41
+ 100
42
+ end
43
+ end
44
+
45
+ def self.max_workers
46
+ ENV['WORKLESS_MAX_WORKERS'].present? ? ENV['WORKLESS_MAX_WORKERS'].to_i : 1
47
+ end
48
+
49
+ def self.min_workers
50
+ ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0
51
+ end
52
+ end
25
53
  end
26
54
  end
27
55
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rush'
2
4
 
3
5
  module Delayed
4
6
  module Workless
5
7
  module Scaler
6
8
  class Local < Base
7
-
8
9
  def self.executable_prefix
9
10
  if defined? Delayed::Compatibility.executable_prefix
10
11
  Delayed::Compatibility.executable_prefix
@@ -14,22 +15,22 @@ module Delayed
14
15
  end
15
16
 
16
17
  def self.up
17
- if self.workers == 0
18
- Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job start -i workless", :background => true)
18
+ if workers == 0
19
+ Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job start -i workless", background: true)
19
20
  sleep 1
20
21
  end
21
22
  true
22
23
  end
23
24
 
24
25
  def self.down
25
- if self.workers > 0 and jobs.count == 0
26
- Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job stop -i workless", :background => true)
26
+ if workers > 0 && jobs.count == 0
27
+ Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job stop -i workless", background: true)
27
28
  end
28
29
  true
29
30
  end
30
31
 
31
32
  def self.workers
32
- Rush::Box.new.processes.filter(:cmdline => /delayed_job start -i workless|delayed_job.workless/).size
33
+ Rush::Box.new.processes.filter(cmdline: /delayed_job start -i workless|delayed_job.workless/).size
33
34
  end
34
35
  end
35
36
  end
@@ -1,17 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module Workless
3
5
  module Scaler
4
-
5
6
  class Null < Base
6
-
7
7
  def self.up
8
8
  end
9
9
 
10
10
  def self.down
11
11
  end
12
-
13
12
  end
14
-
15
13
  end
16
14
  end
17
15
  end
@@ -1 +1,3 @@
1
- require File.dirname(__FILE__) + "/../lib/workless/initialize"
1
+ # frozen_string_literal: true
2
+
3
+ require File.dirname(__FILE__) + '/../lib/workless/initialize'
metadata CHANGED
@@ -1,123 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
+ - davidakachaos
7
8
  - lostboy
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2011-06-30 00:00:00.000000000 Z
12
+ date: 2017-06-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
20
  version: '0'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
- name: heroku-api
29
+ name: platform-api
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rush
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - '>='
46
+ - - ">="
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - '>='
53
+ - - ">="
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: delayed_job
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - '>='
60
+ - - ">="
60
61
  - !ruby/object:Gem::Version
61
62
  version: 2.0.7
62
63
  type: :runtime
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - '>='
67
+ - - ">="
67
68
  - !ruby/object:Gem::Version
68
69
  version: 2.0.7
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: rspec
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - '>='
74
+ - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - '>='
81
+ - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  description: Extension to Delayed Job to enable workers to scale up when needed
84
- email: paul.crabtree@gmail.com
85
+ email: davidakachaos@gmail.com
85
86
  executables: []
86
87
  extensions: []
87
88
  extra_rdoc_files: []
88
89
  files:
89
- - rails/init.rb
90
+ - LICENSE
91
+ - README.md
92
+ - lib/workless.rb
90
93
  - lib/workless/initialize.rb
94
+ - lib/workless/middleware/workless_checker.rb
91
95
  - lib/workless/railtie.rb
92
96
  - lib/workless/scaler.rb
93
97
  - lib/workless/scalers/base.rb
94
98
  - lib/workless/scalers/heroku.rb
95
- - lib/workless/scalers/heroku_cedar.rb
96
99
  - lib/workless/scalers/local.rb
97
100
  - lib/workless/scalers/null.rb
98
- - lib/workless.rb
99
- - LICENSE
100
- - README.md
101
+ - rails/init.rb
101
102
  homepage: http://github.com/lostboy/workless
102
103
  licenses: []
103
104
  metadata: {}
104
- post_install_message:
105
+ post_install_message: |2
106
+
107
+ Workless 2.2.0 introduces a backwards-incompatible change!
108
+ Please update your Heroku config to use WORKLESS_API_KEY instead of HEROKU_API_KEY!!
105
109
  rdoc_options: []
106
110
  require_paths:
107
111
  - lib
108
112
  required_ruby_version: !ruby/object:Gem::Requirement
109
113
  requirements:
110
- - - '>='
114
+ - - ">="
111
115
  - !ruby/object:Gem::Version
112
- version: '0'
116
+ version: 2.2.5
113
117
  required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  requirements:
115
- - - '>='
119
+ - - ">="
116
120
  - !ruby/object:Gem::Version
117
121
  version: 1.3.6
118
122
  requirements: []
119
123
  rubyforge_project:
120
- rubygems_version: 2.0.3
124
+ rubygems_version: 2.4.5.1
121
125
  signing_key:
122
126
  specification_version: 4
123
127
  summary: Use delayed job workers only when theyre needed on Heroku
@@ -1,49 +0,0 @@
1
- require 'heroku-api'
2
-
3
- module Delayed
4
- module Workless
5
- module Scaler
6
- class HerokuCedar < Base
7
- extend Delayed::Workless::Scaler::HerokuClient
8
-
9
- def self.up
10
- client.post_ps_scale(ENV['APP_NAME'], 'worker', self.workers_needed) if self.workers_needed > self.min_workers and self.workers < self.workers_needed
11
- end
12
-
13
- def self.down
14
- client.post_ps_scale(ENV['APP_NAME'], 'worker', self.min_workers) unless self.jobs.count > 0 or self.workers == self.min_workers
15
- end
16
-
17
- def self.workers
18
- client.get_ps(ENV['APP_NAME']).body.count { |p| p["process"] =~ /worker\.\d?/ }
19
- end
20
-
21
- # Returns the number of workers needed based on the current number of pending jobs and the settings defined by:
22
- #
23
- # ENV['WORKLESS_WORKERS_RATIO']
24
- # ENV['WORKLESS_MAX_WORKERS']
25
- # ENV['WORKLESS_MIN_WORKERS']
26
- #
27
- def self.workers_needed
28
- [[(self.jobs.count.to_f / self.workers_ratio).ceil, self.max_workers].min, self.min_workers].max
29
- end
30
-
31
- def self.workers_ratio
32
- if ENV['WORKLESS_WORKERS_RATIO'].present? && (ENV['WORKLESS_WORKERS_RATIO'].to_i != 0)
33
- ENV['WORKLESS_WORKERS_RATIO'].to_i
34
- else
35
- 100
36
- end
37
- end
38
-
39
- def self.max_workers
40
- ENV['WORKLESS_MAX_WORKERS'].present? ? ENV['WORKLESS_MAX_WORKERS'].to_i : 1
41
- end
42
-
43
- def self.min_workers
44
- ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0
45
- end
46
- end
47
- end
48
- end
49
- end