remote_rails_rake_runner 0.9.0 → 1.0.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: 621a556dfc8cff55193453d49b5b4eb1c8fe4c38
4
- data.tar.gz: 7f2b3197dbcf7f25488f24d641309d58db5dea0f
3
+ metadata.gz: 17831862bcbb7eb3e4b7b2d58e4989eebe334ddc
4
+ data.tar.gz: 381aa048a192d599ab521b0b9c4a468748d43f2a
5
5
  SHA512:
6
- metadata.gz: c833ec85f791f78b03264b5fd7351176dc00d13282e2a7e34a158726d81942d62e0927a1de18eae32c8c0d0e3c18b9827924c00348e1afc94ace47d87d928a59
7
- data.tar.gz: e6c07078ce89ab3271f3551ad88af3085dd7f38a39d87d9da1c39030feb74d79531d9f52b4e61664df3c94677f3cd08d94face4a79881e7e1721a5759a9ffe9d
6
+ metadata.gz: fabba42d81551a3c75f37391ef8642d5b50cdaf77ec5e7d09ac900ae171b6aa1e25280d8212c9c2a2ceb1573775fffe944be0d431fee451e8fb5d1a435562b3f
7
+ data.tar.gz: b49bad47f6f6b2ac9ca8309b52e6296a19fe1b663b52f8ef5930cebd92aa2156aeade5ecbc80c77cad98ae278e896242181ee615a198af2f34c497e8b345c6f6
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  The goal to deal with one problem: The startup time of a big Rails
4
4
  project when running a functional suite across multiple servers.
5
5
 
6
+ [![Circle CI](https://circleci.com/gh/gaqzi/remote_rails_rake_runner/tree/master.svg?style=svg)](https://circleci.com/gh/gaqzi/remote_rails_rake_runner/tree/master)
7
+ [![Coverage Status](https://coveralls.io/repos/gaqzi/remote_rails_rake_runner/badge.svg?branch=master&service=github)](https://coveralls.io/github/gaqzi/remote_rails_rake_runner?branch=master)
8
+ [![Gem Version](https://badge.fury.io/rb/remote_rails_rake_runner.svg)](http://badge.fury.io/rb/remote_rails_rake_runner)
9
+
6
10
  ## Background
7
11
  The project this lil' app was started on is running a Cucumber suite
8
12
  that spans a total of 10 concurrent runners, all of whom need data at
@@ -35,13 +39,18 @@ end
35
39
  ## Configuration
36
40
 
37
41
  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`.
42
+ `Rails.application.config.remote_rake_runner_rakefile_path` which defaults to
43
+ `Rails.root.join('Rakefile').to_s`.
39
44
 
40
45
  ## Usage
41
46
 
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.
47
+ The app exposes two endpoints, a listing of all the rake tasks and the actual
48
+ runner. To run a task with arguments just put the arguments in into the argument
49
+ `args` separated by commas. The task will not be considered successful if it
50
+ raises an exception, otherwise it's assumed to have been successful.
51
+
52
+ To override an environment variable for one task run set the variable in the
53
+ `environment` variable which acts like a hash.
45
54
 
46
55
  If you mount the app under `/rake` as suggested above:
47
56
 
@@ -51,8 +60,19 @@ $ curl http://localhost:3000/rake
51
60
 
52
61
  $ curl http://localhost:3000/rake/simple:hello -d args=Björn
53
62
  {"success":true,"output":"Hello Björn!\n"}
63
+
64
+ $ curl http://localhost:3000/rake/simple:hello_environment -d 'environment[name]=Björn&args=Ahlo'
65
+ {"success":true,"output":"Ahlo Björn!\n"}
54
66
  ```
55
67
 
68
+ ## Arguments
69
+
70
+ * `args`: A comma separated list string of arguments passed to the rake task,
71
+ like on the command line
72
+ * `environment`: A hash of overridden values.
73
+ Example in Ruby: `{environment: {name: 'Björn'}}` or in curl
74
+ `environment[name]=Björn`.
75
+
56
76
  ## Acknowledgements
57
77
 
58
78
  The running and capturing of output that was taken from
@@ -2,7 +2,8 @@ require_dependency 'remote_rails_rake_runner/application_controller'
2
2
 
3
3
  module RemoteRailsRakeRunner
4
4
  class RunnerController < ApplicationController
5
- before_filter :load_rake
5
+ before_action :load_rake
6
+ skip_before_action :verify_authenticity_token rescue ArgumentError
6
7
 
7
8
  def index
8
9
  tasks = Rake.application.tasks.map do |t|
@@ -18,20 +19,30 @@ module RemoteRailsRakeRunner
18
19
 
19
20
  def run
20
21
  success = true
21
- task = Rake.application.tasks.find { |t| t.name == params[:task] }
22
+ rake_tasks = Rake.application.tasks
23
+ task = rake_tasks.find { |t| t.name == params[:task] }
22
24
  return head :not_found unless task
23
25
 
24
26
  begin
25
- output = capture_stdout { task.invoke(*(params[:args] || '').split(',')) }
27
+ output = capture_stdout do
28
+ override_env(environment_params) { task.invoke(*(params[:args] || '').split(',')) }
29
+ end
26
30
  rescue => e
27
31
  success = false
28
32
  output = e.inspect
33
+ ensure
34
+ rake_tasks.each { |task| task.reenable }
29
35
  end
30
36
 
31
37
  render json: {success: success, output: output}
32
38
  end
33
39
 
34
40
  private
41
+ def environment_params
42
+ params[:environment].permit! if params[:environment].respond_to?(:permit!)
43
+ params[:environment]
44
+ end
45
+
35
46
  def capture_stdout
36
47
  previous, $stdout = $stdout, StringIO.new
37
48
  yield
@@ -40,11 +51,25 @@ module RemoteRailsRakeRunner
40
51
  $stdout = previous
41
52
  end
42
53
 
54
+ def override_env(variables)
55
+ unless variables.blank?
56
+ begin
57
+ previous = ENV.to_h
58
+ ENV.update(variables)
59
+ yield
60
+ ensure
61
+ ENV.replace(previous)
62
+ end
63
+ else
64
+ yield
65
+ end
66
+ end
67
+
43
68
  def load_rake
44
- return if defined? Rake
69
+ return if defined? Rake.application
45
70
 
46
71
  require 'rake'
47
- load Rails.application.config.remote_rake_runner_rakefile_path || Rails.root.join('Rakefile').to_s
72
+ load Rails.application.config.try(:remote_rake_runner_rakefile_path) || Rails.root.join('Rakefile').to_s
48
73
  end
49
74
  end
50
75
  end
@@ -1,3 +1,3 @@
1
1
  module RemoteRailsRakeRunner
2
- VERSION = '0.9.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,68 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_rails_rake_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Andersson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '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
26
  version: '0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - ba@sanitarium.se
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
34
37
  - app/controllers/remote_rails_rake_runner/application_controller.rb
35
38
  - app/controllers/remote_rails_rake_runner/runner_controller.rb
36
39
  - config/routes.rb
40
+ - lib/remote_rails_rake_runner.rb
37
41
  - lib/remote_rails_rake_runner/engine.rb
38
42
  - lib/remote_rails_rake_runner/version.rb
39
- - lib/remote_rails_rake_runner.rb
40
43
  - lib/tasks/remote_rails_rake_runner_tasks.rake
41
- - MIT-LICENSE
42
- - Rakefile
43
- - README.md
44
44
  homepage: https://github.com/gaqzi/remote_rails_rake_runner
45
45
  licenses:
46
46
  - MIT
47
47
  metadata: {}
48
- post_install_message:
48
+ post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
52
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubyforge_project:
64
- rubygems_version: 2.0.14
65
- signing_key:
63
+ rubyforge_project:
64
+ rubygems_version: 2.5.2.3
65
+ signing_key:
66
66
  specification_version: 4
67
67
  summary: A simple API endpoint to run your rake tasks in the Rails context.
68
68
  test_files: []