workless_revived 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -130
- metadata +7 -74
- data/LICENSE +0 -20
- data/lib/workless/initialize.rb +0 -7
- data/lib/workless/middleware/workless_checker.rb +0 -30
- data/lib/workless/railtie.rb +0 -11
- data/lib/workless/scaler.rb +0 -61
- data/lib/workless/scalers/base.rb +0 -21
- data/lib/workless/scalers/heroku.rb +0 -55
- data/lib/workless/scalers/local.rb +0 -38
- data/lib/workless/scalers/null.rb +0 -15
- data/lib/workless_revived.rb +0 -6
- data/rails/init.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc48e65a2dfdc03c5d0d766f95b4e523afcf57f5
|
4
|
+
data.tar.gz: 95bd2aa297cb10a8c2b1bcb5b6cf5c2500303d6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2233d9fbcbcdc8b4a2b3af19623fc326dac7868ad103a02b5acae3ca78c2c5621ec5f6067c7719465595a20ad4489bc89ed11bf02f0b2b9f586f507bee9c4df1
|
7
|
+
data.tar.gz: 72f0300443bcd38f1669b62df4c07e8b5edca8cbce754d9be8c85e44e52e52254bacb7c23e5cd3d70ba971b2b29d98e151b365c77720493f95c1f83bdc8c5ae8
|
data/README.md
CHANGED
@@ -1,132 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# Workless Revived is deprecated!
|
2
|
+
This gem has been deprecated! [Workless](https://github.com/lostboy/workless) is back!
|
3
|
+
Please adjust your Gemfiles to point to the original Workless gem, it contains all adjustments from this fork!
|
4
4
|
|
5
|
-
|
5
|
+
I will start closing issues here and reffer you to the original gem. @lostboy and myself are currently maintaining the original gem.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
This is an addon for delayed_job (> 2.0.0) http://github.com/collectiveidea/delayed_job
|
10
|
-
It is designed to be used when you're using Heroku as a host and have the need to do background work with delayed job but you don't want to leave the workers running all the time as it costs money.
|
11
|
-
|
12
|
-
By adding the gem to your project and configuring our Heroku app with some config variables workless should do the rest.
|
13
|
-
|
14
|
-
:warning: **[The Legacy API will be sunset on April 15th, 2017](https://devcenter.heroku.com/changelog-items/862)** :warning:
|
15
|
-
Please upgrade to version 2.0.0 as soon as you can. Version 2.0.0 is released on March 1st, 2017.
|
16
|
-
|
17
|
-
## Heroku Stack Heroku-16 update
|
18
|
-
Version 2.1.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!
|
19
|
-
|
20
|
-
## Updates
|
21
|
-
|
22
|
-
* Version 2.1.0 CHANGE! In order to be compatible with the latest Heroku Stack (see [#11](https://github.com/davidakachaos/workless_revived/issues/11) by @unmultimedio ) I have changed the name for the HEROKU_API_KEY variable to WORKLESS_API_KEY
|
23
|
-
* Version 2.0.0 Updated to use latest version of the Heroku API. Drops support for old style Heroku
|
24
|
-
* Version 1.3.0 DROPS SUPPORT FOR OLDER RUBY AND RAILS VERSIONS!
|
25
|
-
* Version 1.2.5 Added middleware to check on delayed jobs, fixed Rails 5 support
|
26
|
-
* Version 1.2.4 drops support for older versions!
|
27
|
-
* Version 1.2.3 replaces multiple commit callback with two callbacks for compatibility by @lostboy
|
28
|
-
* Version 1.2.2 includes after_commit fix by @collectiveip
|
29
|
-
* Version 1.2.1 includes support for Rails 4 & DJ 4 by @florentmorin
|
30
|
-
* Version 1.2.0 includes new support for Sequel by @davidakachaos
|
31
|
-
* Version 1.1.3 includes changes by @radanskoric to reduce number of heroku api calls
|
32
|
-
* Version 1.1.2 includes a change by @davidakachaos to scale workers using after_commit
|
33
|
-
* Version 1.1.1 includes a fix from @filiptepper and @fixr to correctly scale workers
|
34
|
-
* Version 1.1.0 has been released, this adds support for scaling using multiple workers thanks to @jaimeiniesta and @davidakachaos.
|
35
|
-
* Version 1.0.0 has been released, this brings compatibility with delayed_job 3 and compatibility with Rails 2.3.x and up.
|
36
|
-
|
37
|
-
## Compatibility
|
38
|
-
|
39
|
-
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
|
40
|
-
|
41
|
-
Ruby | Rails | Delayed Job
|
42
|
-
---------- | ------ | -----
|
43
|
-
2.2.5 | 4.2 | 2.1.4
|
44
|
-
2.3.1 | 5.0 | 4.1.2
|
45
|
-
2.4.1 | 5.1 | 4.1.3
|
46
|
-
|
47
|
-
## Installation
|
48
|
-
|
49
|
-
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
|
50
|
-
|
51
|
-
### For rails 4.x with latest delayed_job 3.x using active record
|
52
|
-
|
53
|
-
<pre>
|
54
|
-
gem "delayed_job_active_record"
|
55
|
-
gem "workless_revived", "~> 1.2.4"
|
56
|
-
</pre>
|
57
|
-
|
58
|
-
### For rails 5.x with latest delayed_job 3.x using active record
|
59
|
-
|
60
|
-
<pre>
|
61
|
-
gem "delayed_job_active_record"
|
62
|
-
gem "workless_revived", "~> 1.2.4"
|
63
|
-
</pre>
|
64
|
-
|
65
|
-
|
66
|
-
If you don't specify delayed_job in your Gemfile workless will bring it in, most likely the latest version (4.1.2)
|
67
|
-
|
68
|
-
Add your Heroku app name / [API key](https://devcenter.heroku.com/articles/authentication) as config vars to your Heroku instance.
|
69
|
-
|
70
|
-
<pre>
|
71
|
-
heroku config:add WORKLESS_API_KEY=yourapikey APP_NAME=yourherokuappname
|
72
|
-
</pre>
|
73
|
-
|
74
|
-
## Failing Jobs
|
75
|
-
|
76
|
-
In the case of failed jobs Workless will only shut down the dj worker if all attempts have been tried. By default Delayed Job will try 25 times to process a job with ever increasing time delays between each unsucessful attempt. Because of this Workless configures Delayed Job to try failed jobs only 3 times to reduce the amount of time a worker can be running while trying to process them.
|
77
|
-
|
78
|
-
## Configuration
|
79
|
-
|
80
|
-
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:
|
81
|
-
|
82
|
-
<pre>
|
83
|
-
config.after_initialize do
|
84
|
-
Delayed::Job.scaler = :null
|
85
|
-
end
|
86
|
-
</pre>
|
87
|
-
|
88
|
-
There are three other scalers included. Note that if you are running on the Aspen or Bamboo stacks on Heroku and you don't explicitly specify the scaler, the heroku scaler will be used automatically.
|
89
|
-
|
90
|
-
<pre>
|
91
|
-
Delayed::Job.scaler = :heroku
|
92
|
-
Delayed::Job.scaler = :heroku
|
93
|
-
Delayed::Job.scaler = :local
|
94
|
-
</pre>
|
95
|
-
|
96
|
-
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).
|
97
|
-
|
98
|
-
The heroku scaler works on the Aspen and Bamboo stacks while the heroku_cedar scaler only works on the new Cedar stack.
|
99
|
-
|
100
|
-
## Scaling to multiple workers
|
101
|
-
|
102
|
-
As an experimental feature for the Cedar stack, Workless can scale to more than 1 worker based on the current work load. You just need to define these config variables on your app, setting the values you want:
|
103
|
-
|
104
|
-
<pre>
|
105
|
-
heroku config:add WORKLESS_MAX_WORKERS=10
|
106
|
-
heroku config:add WORKLESS_MIN_WORKERS=0
|
107
|
-
heroku config:add WORKLESS_WORKERS_RATIO=50
|
108
|
-
</pre>
|
109
|
-
|
110
|
-
In this example, it will scale up to a maximum of 10 workers, firing up 1 worker for every 50 jobs on the queue. The minimum will be 0 workers, but you could set it to a higher value if you want.
|
111
|
-
|
112
|
-
## How does Workless work?
|
113
|
-
|
114
|
-
- `Delayed::Workless::Scaler` is mixed into the `Delayed::Job` class, which adds a bunch of callbacks to it.
|
115
|
-
- When a job is created on the database, a `create` callback starts a worker.
|
116
|
-
- The worker runs the job, which removes it from the database.
|
117
|
-
- A `destroy` callback stops the worker.
|
118
|
-
|
119
|
-
## Note on Patches/Pull Requests
|
120
|
-
|
121
|
-
* Please fork the project.
|
122
|
-
* Make your feature addition or bug fix.
|
123
|
-
* Commit, do not mess with rakefile, version, or history.
|
124
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
125
|
-
* Send me a pull request.
|
126
|
-
|
127
|
-
## Copyright
|
128
|
-
|
129
|
-
Copyright (c) 2010 lostboy.
|
130
|
-
Copyright (c) 2016 davidakachaos.
|
131
|
-
|
132
|
-
See LICENSE for details.
|
7
|
+
# Thanks for all the fish
|
8
|
+
And I will see you at [our new home](https://github.com/lostboy/workless)
|
metadata
CHANGED
@@ -1,103 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workless_revived
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- davidakachaos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: workless
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: platform-api
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rush
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: delayed_job
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.0.7
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.0.7
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
26
|
+
version: 2.2.0
|
83
27
|
description: Extension to Delayed Job to enable workers to scale up when needed
|
84
28
|
email: davidakachaos@gmail.com
|
85
29
|
executables: []
|
86
30
|
extensions: []
|
87
31
|
extra_rdoc_files: []
|
88
32
|
files:
|
89
|
-
- LICENSE
|
90
33
|
- README.md
|
91
|
-
- lib/workless/initialize.rb
|
92
|
-
- lib/workless/middleware/workless_checker.rb
|
93
|
-
- lib/workless/railtie.rb
|
94
|
-
- lib/workless/scaler.rb
|
95
|
-
- lib/workless/scalers/base.rb
|
96
|
-
- lib/workless/scalers/heroku.rb
|
97
|
-
- lib/workless/scalers/local.rb
|
98
|
-
- lib/workless/scalers/null.rb
|
99
|
-
- lib/workless_revived.rb
|
100
|
-
- rails/init.rb
|
101
34
|
homepage: http://github.com/davidakachaos/workless_revived
|
102
35
|
licenses: []
|
103
36
|
metadata: {}
|
@@ -113,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
46
|
requirements:
|
114
47
|
- - ">="
|
115
48
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
49
|
+
version: '0'
|
117
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
51
|
requirements:
|
119
52
|
- - ">="
|
@@ -121,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
54
|
version: 1.3.6
|
122
55
|
requirements: []
|
123
56
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.6.11
|
125
58
|
signing_key:
|
126
59
|
specification_version: 4
|
127
60
|
summary: Use delayed job workers only when theyre needed on Heroku
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 lostboy
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/workless/initialize.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Delayed::Worker.max_attempts ||= 3
|
4
|
-
Delayed::Backend::ActiveRecord::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::ActiveRecord::Job)
|
5
|
-
Delayed::Backend::Mongoid::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::Mongoid::Job)
|
6
|
-
Delayed::Backend::MongoMapper::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::MongoMapper::Job)
|
7
|
-
Delayed::Backend::Sequel::Job.send(:include, Delayed::Workless::Scaler) if defined?(Delayed::Backend::Sequel::Job)
|
@@ -1,30 +0,0 @@
|
|
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
|
data/lib/workless/railtie.rb
DELETED
data/lib/workless/scaler.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Delayed
|
4
|
-
module Workless
|
5
|
-
module Scaler
|
6
|
-
autoload :Heroku, 'workless/scalers/heroku'
|
7
|
-
autoload :Local, 'workless/scalers/local'
|
8
|
-
autoload :Null, 'workless/scalers/null'
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
base.send :extend, ClassMethods
|
12
|
-
if base.to_s =~ /ActiveRecord/
|
13
|
-
base.class_eval do
|
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
|
24
|
-
elsif base.to_s =~ /Sequel/
|
25
|
-
base.send(:define_method, 'after_destroy') do
|
26
|
-
super
|
27
|
-
self.class.scaler.down
|
28
|
-
end
|
29
|
-
base.send(:define_method, 'after_create') do
|
30
|
-
super
|
31
|
-
self.class.scaler.up
|
32
|
-
end
|
33
|
-
base.send(:define_method, 'after_update') do
|
34
|
-
super
|
35
|
-
self.class.scaler.down
|
36
|
-
end
|
37
|
-
else
|
38
|
-
base.class_eval do
|
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? }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
module ClassMethods
|
47
|
-
def scaler
|
48
|
-
@scaler ||= if ENV.include?('WORKLESS_API_KEY')
|
49
|
-
Scaler::Heroku
|
50
|
-
else
|
51
|
-
Scaler::Local
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def scaler=(scaler)
|
56
|
-
@scaler = "Delayed::Workless::Scaler::#{scaler.to_s.camelize}".constantize
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'delayed_job'
|
4
|
-
|
5
|
-
module Delayed
|
6
|
-
module Workless
|
7
|
-
module Scaler
|
8
|
-
class Base
|
9
|
-
def self.jobs
|
10
|
-
Delayed::Job.where(failed_at: nil)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module HerokuClient
|
15
|
-
def client
|
16
|
-
@client ||= ::PlatformAPI.connect(ENV['WORKLESS_API_KEY'])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'platform-api'
|
4
|
-
|
5
|
-
module Delayed
|
6
|
-
module Workless
|
7
|
-
module Scaler
|
8
|
-
class Heroku < Base
|
9
|
-
extend Delayed::Workless::Scaler::HerokuClient
|
10
|
-
|
11
|
-
def self.up
|
12
|
-
return unless workers_needed > min_workers && workers < workers_needed
|
13
|
-
updates = { "quantity": workers_needed }
|
14
|
-
client.formation.update(ENV['APP_NAME'], 'worker', updates)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.down
|
18
|
-
return if workers == workers_needed
|
19
|
-
updates = { "quantity": workers_needed }
|
20
|
-
client.formation.update(ENV['APP_NAME'], 'worker', updates)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.workers
|
24
|
-
client.formation.info(ENV['APP_NAME'], 'worker')['quantity'].to_i
|
25
|
-
end
|
26
|
-
|
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
|
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
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rush'
|
4
|
-
|
5
|
-
module Delayed
|
6
|
-
module Workless
|
7
|
-
module Scaler
|
8
|
-
class Local < Base
|
9
|
-
def self.executable_prefix
|
10
|
-
if defined? Delayed::Compatibility.executable_prefix
|
11
|
-
Delayed::Compatibility.executable_prefix
|
12
|
-
else
|
13
|
-
'script'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.up
|
18
|
-
if workers == 0
|
19
|
-
Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job start -i workless", background: true)
|
20
|
-
sleep 1
|
21
|
-
end
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.down
|
26
|
-
if workers > 0 && jobs.count == 0
|
27
|
-
Rush::Box.new[Rails.root].bash("#{executable_prefix}/delayed_job stop -i workless", background: true)
|
28
|
-
end
|
29
|
-
true
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.workers
|
33
|
-
Rush::Box.new.processes.filter(cmdline: /delayed_job start -i workless|delayed_job.workless/).size
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/workless_revived.rb
DELETED
@@ -1,6 +0,0 @@
|
|
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)
|
data/rails/init.rb
DELETED