adept_scale_active_job 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +3 -0
- data/README.md +48 -0
- data/Rakefile +33 -0
- data/lib/adept_scale_active_job.rb +50 -0
- data/lib/adept_scale_active_job/version.rb +3 -0
- data/lib/tasks/adept_scale_active_job_tasks.rake +4 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e4e3a36d958c31232ac69c135b4501541914b997
|
4
|
+
data.tar.gz: cf5a7f10fe02baef20f99764331923f500e4574c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 126c6a0f26c6206a40a276ee0cebddb82d10f824e5f6cfd26c15ff1c56726aaf1fe4ed41286ef92ceac34a152d60e20eb118515a9e4ac376158e83b9c21a671f
|
7
|
+
data.tar.gz: c1f5aea8cf560365c0a95a51b05d1006b0ff39ba3eb1ea96ed78005754d1de31eff8acc8f47b1f0a771a92fff0b7a2565621dc0a68b62c787fed9db358158c91
|
data/LICENSE
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Copyright 2018 AdeptLabs INC, All rights reserved.
|
2
|
+
|
3
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# AdeptScaleActiveJob
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
This plugin extends the `ActiveJob::Base` class in order to insert ADEPT_SCALE tagged logs into your app's STDOUT. The tags include ```['JOB_QUEUED', 'JOB_STARTING', 'JOB_STATUS', 'JOB_COMPLETE', 'JOB_FAILED']``` and are used by AdeptScale to keep the current state of your job queue for the purpose of scaling worker dynos.
|
6
|
+
More explanation of how these work can be found on our [Documentation](https://devcenter.heroku.com/articles/adept-scale)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'adept_scale_active_job'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
```bash
|
22
|
+
$ gem install adept_scale_active_job
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
### Inherit Job Model from AdeptScaleActiveJob
|
28
|
+
After installation, change any ActiveJob based object to inherit from ```AdeptScaleActiveJob::Base``` instead of the default ```AdeptScaleActiveJob::Base```.
|
29
|
+
For example, the simplest method would be at the ApplicationJob level:
|
30
|
+
```
|
31
|
+
# /app/jobs/applicaiton_job.rb
|
32
|
+
|
33
|
+
class ApplicationJob < AdeptScaleActiveJob::Base
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### Procfile
|
38
|
+
In delivered form this gem assumes that the job queue has the same name as the dyno it runs on. If this is not the case, you will need to make necessary changes to support your particular use case.
|
39
|
+
Future plans include adding support for a procfile where you can define a mapping between queue names and which dyno types they run on. Contributions in this regard are greatly welcome.
|
40
|
+
|
41
|
+
## Contribution
|
42
|
+
|
43
|
+
We encourage all contributors and love to hear your feedback. Hopefully this will be a bare-bones example for similar plugins in other languages.
|
44
|
+
|
45
|
+
## License
|
46
|
+
Copyright 2018 AdeptLabs INC, All rights reserved.
|
47
|
+
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'AdeptScaleActiveJob'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AdeptScaleActiveJob
|
2
|
+
class Base < ActiveJob::Base
|
3
|
+
rescue_from Exception, :with => :log_exception
|
4
|
+
|
5
|
+
def adept_scale_logger
|
6
|
+
@@adept_scale_logger ||= Logger.new(STDOUT)
|
7
|
+
end
|
8
|
+
|
9
|
+
#@param BasicProcessJob | [@job_id, @queue_name, @priority, @executions, @scheduled_at, @provider_job_id]
|
10
|
+
after_enqueue do |job|
|
11
|
+
#NOTE: For this basic-use gem we will assume the queue_name is also the dyno type.
|
12
|
+
#TODO: either figure out how to obtain the queue_name->dyno_type mapping from config, or build an initializer for the user to set it themselves
|
13
|
+
job_params = {:dyno_type => job.queue_name, :scheduled_at => job.scheduled_at}
|
14
|
+
adept_scale_logger.add(6, "ADEPT_SCALE JOB_QUEUED #{format_params job_params}")
|
15
|
+
end
|
16
|
+
|
17
|
+
#@param BasicProcessJob | [@job_id, @queue_name, @priority, @executions, @provider_job_id]
|
18
|
+
before_perform do |job|
|
19
|
+
job_params = {:job_id => job.provider_job_id}
|
20
|
+
adept_scale_logger.add(6, "ADEPT_SCALE JOB_STARTING #{format_params job_params}")
|
21
|
+
end
|
22
|
+
|
23
|
+
#@param BasicProcessJob | [@job_id, @queue_name, @priority, @executions, @provider_job_id]
|
24
|
+
after_perform do |job|
|
25
|
+
job_params = {:job_id => job.provider_job_id}
|
26
|
+
adept_scale_logger.add(6, "ADEPT_SCALE JOB_COMPLETE #{format_params job_params}")
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
#Catch all Object level base Exceptions, if we can, so we can remove them from the running process list
|
31
|
+
def log_exception e
|
32
|
+
#Don't log the exception to Adept, this is the clients' private business.
|
33
|
+
adept_scale_logger.add(6, "ADEPT_SCALE JOB_FAILED")
|
34
|
+
#reraise so as to hopefully not interefere with other error handling
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
|
38
|
+
#@param BasicProcessJob | [@job_id, @queue_name, @priority, @executions, @scheduled_at, @provider_job_id]
|
39
|
+
#ie. #<BasicProcessJob:0x00007fd0218ab3a0 @arguments=[30], @job_id="4970c4ee-67b7-4cf6-9519-f1bc4513fa4b", @queue_name="worker", @priority=nil, @executions=0, @scheduled_at=1525461719.492488, @provider_job_id="1da86e157a6cd6dc21791b38">
|
40
|
+
#@param Hash | a key/value hash of our params.
|
41
|
+
def format_params job_params
|
42
|
+
#Only allow these params to be stringified
|
43
|
+
params = [:dyno_type, :job_id, :scheduled_at, :scheduled_at, :total_queue, :running_jobs]
|
44
|
+
params.reduce([]) do |ary, param|
|
45
|
+
ary << "#{param}=#{job_params[param]}" if job_params.has_key?(param)
|
46
|
+
ary
|
47
|
+
end.join(' ')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adept_scale_active_job
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Burnett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Wrapper for ActiveJob to provide tags to STDOUT for use with AdeptScale
|
42
|
+
worker scaling.
|
43
|
+
email:
|
44
|
+
- ''
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- lib/adept_scale_active_job/version.rb
|
50
|
+
- lib/adept_scale_active_job.rb
|
51
|
+
- lib/tasks/adept_scale_active_job_tasks.rake
|
52
|
+
- LICENSE
|
53
|
+
- Rakefile
|
54
|
+
- README.md
|
55
|
+
homepage: http://adeptscale.com
|
56
|
+
licenses:
|
57
|
+
- Nonstandard
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.14.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: ActiveJob wrapper for AdeptScale
|
79
|
+
test_files: []
|