dynosaur 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4143dd8410c842565956f544fca8c5edcfc2752c
4
+ data.tar.gz: 4d24ef4ccbc6a6fe6742da89b1f39585f7c0759f
5
+ SHA512:
6
+ metadata.gz: c153e19d0bdeea037f565d44a2bec05d8c2e8911eb2c4e73f39ca53ec9ba73d12bf1b4c6f795705eb11d48c635a503d567ad84988e5c2350f14b1de45ed26975
7
+ data.tar.gz: f7257bd138dc326167639de8665e018bc2d216b9c2746c268b8d41a530abbb781cbbc11d874467cb2e4e0966635e979fc4beb28ba7cc3bc5ee3031c66973cb75
@@ -0,0 +1,8 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+ ratings:
5
+ paths:
6
+ - "**.rb"
7
+ exclude_paths:
8
+ - spec/**/*
@@ -0,0 +1,2 @@
1
+ dynosaur-*.gem
2
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require 'spec_helper'
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ code_climate:
5
+ repo_token:
6
+ secure: 55K8ryeXRmlzUy8PtRFh1nQpZhQXo1sEySBF72fWVPMUrtj2BedCLMb5vJsXBZpW6a9p7wYktjIEHAzIH5kTxVlO1Bzm01JZxUQOTnYZDz96R5CL/dgx1G0trSe6QsGpYm3qfgEW/7NX4qr7Nydz2JpiOvzrX1I3yBOB4ILJ7oseMMXVQZ/o5yFb6FM754MkRqdwmAKPcJAfSi6BVeXfycQCAaE3+42Tr/z0lAPpWVjToH9NK0BqVqTgNcLor4INzY25JntiSRXoD9X3CZYaFwD0zfigekeOHb7B2jr64vxJwjVzxiQzNe3D1il9+b8Do/A1gwc9gouMvjPEhSzr7evIh8LviaSoIAHCkANn/jNsRYDeeK3s45eavaVkXJd53FbDQtUOl2RxBXA0CbsnmSmXtosmY2ZdHhTZNOSOJOChXPGKjpVr3kVYMEOElaMg3am3VTDSXc/eiD2CTjUl5kkoucN7FgTn1aA369iHieFWao+pzimH41As37GGDbF9tESuHAsO9MjhQPPuD3ztYpdPmQT7std60B7GttE19c37aIYVDUEhhnRLiTIskQi+6ITbZaS+wp131yIXmG7N1SqIaxGC+Scq1NOyKUGMuOqOkJdDSziksLhYh3cYjkc9UBGP80y7NtxpdzDUaM69G0IEJaPwURiwymtDxukrULk=
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dynosaur.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Apartment List, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Dynosaur
2
+
3
+ Run a rake task in a separate process (locally or on Heroku)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dynosaur'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dynosaur
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ Dynosaur::Client::HerokuClient.configure do |config|
25
+ config.app_name = '<Heroku app name>'
26
+ config.api_key = '<Heroku API key>'
27
+ end
28
+
29
+ dyno = Dynosaur::Process::Heroku.new(task: 'session:destroy', args: [2500])
30
+ dyno.start
31
+ # => run.9876
32
+
33
+ local_process = Dynosaur::Process::Local.new(task: 'session:destroy', args: [2500])
34
+ local_process.start
35
+ # => 48345
36
+ ```
37
+
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/dynosaur/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
@@ -0,0 +1,26 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
8
+
9
+ task :echo, [:arg1, :arg2] do |_task, args|
10
+ puts %Q(ARG1: "#{args[:arg1]}")
11
+ puts %Q(ARG2: "#{args[:arg2]}")
12
+ end
13
+
14
+ task :sleep, [:duration] do |_task, args|
15
+ File.open('/tmp/sleep', 'w') do |file|
16
+ file.puts "Sleeping"
17
+ args[:duration].to_i.times do
18
+ sleep(1)
19
+ file.print('.')
20
+ file.flush
21
+ end
22
+ file.print("\n")
23
+ file.puts "Awake"
24
+ file.flush
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'dynosaur'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dynosaur/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dynosaur'
8
+ spec.version = Dynosaur::VERSION
9
+ spec.authors = ['Tom Collier']
10
+ spec.email = ['collier@apartmentlist.com']
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = 'Run a rake task in a separate process (locally or on Heroku)'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f =~ %r{^(spec)/} }
16
+
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'platform-api', '~> 0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.8'
23
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
24
+ spec.add_development_dependency 'pry-byebug', '~> 3'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3'
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'dynosaur/version'
2
+ require 'dynosaur/process/heroku'
3
+ require 'dynosaur/process/local'
4
+
5
+ # Spin up a rake task in a separate process
6
+ module Dynosaur
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'platform-api'
2
+
3
+ # A wrapper for the Heroku Platform API gem.
4
+ module Dynosaur
5
+ module Client
6
+ module HerokuClient
7
+ def self.config
8
+ @config ||= Config.new
9
+ end
10
+
11
+ def self.configure
12
+ yield config if block_given?
13
+ end
14
+
15
+ def self.client
16
+ PlatformAPI.connect_oauth(api_key)
17
+ end
18
+
19
+ def self.app_name
20
+ config.app_name || fail('app_name must be set in the config')
21
+ end
22
+
23
+ def self.api_key
24
+ config.api_key || fail('api_key must be set in the config')
25
+ end
26
+
27
+ private
28
+
29
+ Config = Struct.new(:api_key, :app_name)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ require 'shellwords'
2
+
3
+ module Dynosaur
4
+ class Process
5
+ def initialize(task:, args: [], opts: {})
6
+ @task = task
7
+ @args = args
8
+ after_initialize(opts)
9
+ end
10
+
11
+ def start
12
+ fail NotImplementedError, 'This method must be implemented in a subclass'
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :args, :task
18
+
19
+ def after_initialize(opts)
20
+ # Do nothing so subclasses don't have to override if they want a no-op
21
+ end
22
+
23
+ def rake_command
24
+ formatted_args = args.map do |arg|
25
+ arg.is_a?(String) ? arg.shellescape : arg
26
+ end.join(',')
27
+ task_with_args = args.empty? ? task : "#{task}[#{formatted_args}]"
28
+ "rake #{task_with_args} --trace"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ require 'dynosaur/client/heroku_client'
2
+
3
+ require_relative '../process'
4
+
5
+ # Start a detached rake task on a one-off dyno
6
+ module Dynosaur
7
+ class Process
8
+ class Heroku < Process
9
+ # Valid dyno sizes under Heroku's new pricing model
10
+ module Size
11
+ STANDARD_1X = 'standard-1X'.freeze
12
+ STANDARD_2X = 'standard-2X'.freeze
13
+ PERFORMANCE_M = 'performance-m'.freeze
14
+ PERFORMANCE_L = 'performance-l'.freeze
15
+ end
16
+
17
+ # Valid dyno sizes under Heroku's old pricing model
18
+ module DeprecatedSize
19
+ STANDARD_1X = '1X'.freeze
20
+ STANDARD_2X = '2X'.freeze
21
+ PERFORMANCE = 'PX'.freeze
22
+ end
23
+
24
+ def start
25
+ app_name = Dynosaur::Client::HerokuClient.app_name
26
+ dyno_accessor = Dynosaur::Client::HerokuClient.client.dyno
27
+ create_opts = { command: rake_command, attach: false }
28
+ create_opts[:size] = size if size
29
+ response = dyno_accessor.create(app_name, create_opts)
30
+ response['name']
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :size
36
+
37
+ def after_initialize(opts)
38
+ @size = opts[:size]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../process'
2
+
3
+ module Dynosaur
4
+ class Process
5
+ class Local < Process
6
+ def start
7
+ pid = ::Process.spawn(rake_command)
8
+ ::Process.detach(pid)
9
+ pid
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ # Gem version number
2
+ module Dynosaur
3
+ VERSION = '0.1.0'
4
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynosaur
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Collier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: platform-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ description:
98
+ email:
99
+ - collier@apartmentlist.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".codeclimate.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - dynosaur.gemspec
116
+ - lib/dynosaur.rb
117
+ - lib/dynosaur/client/heroku_client.rb
118
+ - lib/dynosaur/process.rb
119
+ - lib/dynosaur/process/heroku.rb
120
+ - lib/dynosaur/process/local.rb
121
+ - lib/dynosaur/version.rb
122
+ homepage:
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.5
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Run a rake task in a separate process (locally or on Heroku)
146
+ test_files: []
147
+ has_rdoc: