remote_rails_rake_runner 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +23 -0
- data/app/controllers/remote_rails_rake_runner/application_controller.rb +4 -0
- data/app/controllers/remote_rails_rake_runner/runner_controller.rb +50 -0
- data/config/routes.rb +4 -0
- data/lib/remote_rails_rake_runner/engine.rb +9 -0
- data/lib/remote_rails_rake_runner/version.rb +3 -0
- data/lib/remote_rails_rake_runner.rb +4 -0
- data/lib/tasks/remote_rails_rake_runner_tasks.rake +4 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 621a556dfc8cff55193453d49b5b4eb1c8fe4c38
|
4
|
+
data.tar.gz: 7f2b3197dbcf7f25488f24d641309d58db5dea0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c833ec85f791f78b03264b5fd7351176dc00d13282e2a7e34a158726d81942d62e0927a1de18eae32c8c0d0e3c18b9827924c00348e1afc94ace47d87d928a59
|
7
|
+
data.tar.gz: e6c07078ce89ab3271f3551ad88af3085dd7f38a39d87d9da1c39030feb74d79531d9f52b4e61664df3c94677f3cd08d94face4a79881e7e1721a5759a9ffe9d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
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/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Remote Rails Rake Runner
|
2
|
+
|
3
|
+
The goal to deal with one problem: The startup time of a big Rails
|
4
|
+
project when running a functional suite across multiple servers.
|
5
|
+
|
6
|
+
## Background
|
7
|
+
The project this lil' app was started on is running a Cucumber suite
|
8
|
+
that spans a total of 10 concurrent runners, all of whom need data at
|
9
|
+
different times. It was originally developed with rake tasks that was
|
10
|
+
reused from local development and run on the servers remotely through SSH.
|
11
|
+
|
12
|
+
But ~30s startup time per task was starting to have too big of an effect,
|
13
|
+
so this gem was born with the hope of removing all the starting cost while
|
14
|
+
keeping it really simple to reuse the already existing rake tasks.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add to your Gemfile and ensure you mount the app in your routes.
|
19
|
+
|
20
|
+
To your Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'remote_rails_rake_runner'
|
24
|
+
```
|
25
|
+
|
26
|
+
To your `routes.rb`:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Rails.application.routes.draw do
|
30
|
+
|
31
|
+
mount RemoteRailsRakeRunner::Engine => '/rake'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
You can specify the path to your `Rakefile` by setting the option
|
38
|
+
`Rails.application.config.remote_rake_runner_rakefile_path` which defaults to `Rails.root.join('Rakefile').to_s`.
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
The app exposes two endpoints, a listing of all the rake tasks and the actual runner.
|
43
|
+
To run a task with arguments just put the arguments in into the argument `args` separated by commas.
|
44
|
+
The task will not be considered successful if it raises an exception, otherwise it's assumed to have been successful.
|
45
|
+
|
46
|
+
If you mount the app under `/rake` as suggested above:
|
47
|
+
|
48
|
+
```shell
|
49
|
+
$ curl http://localhost:3000/rake
|
50
|
+
[{"name":"about","args":[],"description":null}, …] # a listing of all tasks (like rake -T)
|
51
|
+
|
52
|
+
$ curl http://localhost:3000/rake/simple:hello -d args=Björn
|
53
|
+
{"success":true,"output":"Hello Björn!\n"}
|
54
|
+
```
|
55
|
+
|
56
|
+
## Acknowledgements
|
57
|
+
|
58
|
+
The running and capturing of output that was taken from
|
59
|
+
[this blog post](http://andowebsit.es/blog/noteslog.com/post/how-to-run-rake-tasks-programmatically/)
|
60
|
+
by [Andrea Ercolino].
|
61
|
+
|
62
|
+
[Andrea Ercolino]: https://github.com/aercolino/
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
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 = 'RemoteRailsRakeRunner'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_dependency 'remote_rails_rake_runner/application_controller'
|
2
|
+
|
3
|
+
module RemoteRailsRakeRunner
|
4
|
+
class RunnerController < ApplicationController
|
5
|
+
before_filter :load_rake
|
6
|
+
|
7
|
+
def index
|
8
|
+
tasks = Rake.application.tasks.map do |t|
|
9
|
+
{
|
10
|
+
name: t.to_s,
|
11
|
+
args: t.arg_names,
|
12
|
+
description: t.comment,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
render json: tasks
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
success = true
|
21
|
+
task = Rake.application.tasks.find { |t| t.name == params[:task] }
|
22
|
+
return head :not_found unless task
|
23
|
+
|
24
|
+
begin
|
25
|
+
output = capture_stdout { task.invoke(*(params[:args] || '').split(',')) }
|
26
|
+
rescue => e
|
27
|
+
success = false
|
28
|
+
output = e.inspect
|
29
|
+
end
|
30
|
+
|
31
|
+
render json: {success: success, output: output}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def capture_stdout
|
36
|
+
previous, $stdout = $stdout, StringIO.new
|
37
|
+
yield
|
38
|
+
$stdout.string
|
39
|
+
ensure
|
40
|
+
$stdout = previous
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_rake
|
44
|
+
return if defined? Rake
|
45
|
+
|
46
|
+
require 'rake'
|
47
|
+
load Rails.application.config.remote_rake_runner_rakefile_path || Rails.root.join('Rakefile').to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/config/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remote_rails_rake_runner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Björn Andersson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-07 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: '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
|
+
description:
|
28
|
+
email:
|
29
|
+
- ba@sanitarium.se
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- app/controllers/remote_rails_rake_runner/application_controller.rb
|
35
|
+
- app/controllers/remote_rails_rake_runner/runner_controller.rb
|
36
|
+
- config/routes.rb
|
37
|
+
- lib/remote_rails_rake_runner/engine.rb
|
38
|
+
- lib/remote_rails_rake_runner/version.rb
|
39
|
+
- lib/remote_rails_rake_runner.rb
|
40
|
+
- lib/tasks/remote_rails_rake_runner_tasks.rake
|
41
|
+
- MIT-LICENSE
|
42
|
+
- Rakefile
|
43
|
+
- README.md
|
44
|
+
homepage: https://github.com/gaqzi/remote_rails_rake_runner
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.0.14
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: A simple API endpoint to run your rake tasks in the Rails context.
|
68
|
+
test_files: []
|