iron_response 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +67 -0
- data/Rakefile +10 -0
- data/iron_response.gemspec +21 -0
- data/lib/iron_response/version.rb +3 -0
- data/lib/iron_response.rb +57 -0
- data/test/configuration.rb.example +14 -0
- data/test/rdd_test.rb +20 -0
- data/test/test_helper.rb +6 -0
- data/test/workers/is_prime.rb +12 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Alan deLevie
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# iron_response
|
|
2
|
+
|
|
3
|
+
Provides a response object for IronWorkers.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
require "iron_response"
|
|
7
|
+
|
|
8
|
+
batch = IronResponse::Batch.new
|
|
9
|
+
batch.config[:aws_s3] = {
|
|
10
|
+
access_key_id: 123,
|
|
11
|
+
secret_access_key: 456,
|
|
12
|
+
bucket: "iron_worker"
|
|
13
|
+
}
|
|
14
|
+
batch.config[:iron_io] = {
|
|
15
|
+
project_id: "abc",
|
|
16
|
+
token: "defg"
|
|
17
|
+
}
|
|
18
|
+
batch.worker = "path/to/worker/is_prime"
|
|
19
|
+
batch.params_array = [1..1000].map {|i| {number: i}}
|
|
20
|
+
results = batch.run!
|
|
21
|
+
|
|
22
|
+
p results
|
|
23
|
+
#=> [true, true, true, false, true, false...]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Assumes you have a worker file called `is_prime.rb`:
|
|
27
|
+
```ruby
|
|
28
|
+
require "iron_response"
|
|
29
|
+
|
|
30
|
+
IronResponse::Responder do
|
|
31
|
+
def is_prime?(n)
|
|
32
|
+
("1" * n =~ /^1?$|^(11+?)\1+$/) == 0 ? false : true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
is_prime? params[:number]
|
|
36
|
+
end
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
Don't install this yet. It's just a code sketch so far. Once this library works, these will be the installation instructions:
|
|
42
|
+
|
|
43
|
+
Add this line to your application's Gemfile:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
gem "iron_response"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
And then execute:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
$ bundle
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or install it yourself as:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
$ gem install iron_response
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
1. Fork it
|
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
65
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/iron_response/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Alan deLevie"]
|
|
6
|
+
gem.email = ["adelevie@gmail.com"]
|
|
7
|
+
gem.description = %q{Provides a response object for IronWorker tasks.}
|
|
8
|
+
gem.summary = %q{Provides a response object for IronWorker tasks.}
|
|
9
|
+
gem.homepage = ""
|
|
10
|
+
|
|
11
|
+
gem.files = `git ls-files`.split($\)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
+
gem.name = "iron_response"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = IronResponse::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_dependency "iron_worker_ng"
|
|
19
|
+
gem.add_development_dependency "minitest", "~> 4.7.3"
|
|
20
|
+
gem.add_development_dependency "pry"
|
|
21
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "iron_response/version"
|
|
2
|
+
require "iron_worker_ng"
|
|
3
|
+
|
|
4
|
+
module IronResponse
|
|
5
|
+
class Responder
|
|
6
|
+
def initialize(&block)
|
|
7
|
+
send_data_to_s3(block.call)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def send_data_to_s3(data)
|
|
11
|
+
p "pretending to send #{data} to s3"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Batch
|
|
16
|
+
attr_accessor :config
|
|
17
|
+
attr_accessor :worker
|
|
18
|
+
attr_accessor :params_array
|
|
19
|
+
attr_accessor :auto_update_worker
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@config = {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def worker_name
|
|
26
|
+
@worker.split("/").last
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run!
|
|
30
|
+
@client = IronWorkerNG::Client.new(@config[:iron_io])
|
|
31
|
+
|
|
32
|
+
if @auto_update_worker
|
|
33
|
+
create_code!
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
pids = params_array.map do |params|
|
|
37
|
+
params[:aws_s3] = @config[:aws_s3]
|
|
38
|
+
@client.tasks.create(worker_name, params)._id
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
pids.map do |pid|
|
|
42
|
+
get_response_from_pid(@client.tasks.wait_for(pid))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_response_from_pid(pid)
|
|
47
|
+
"FakeResponseFromPid:#{pid}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def create_code!
|
|
51
|
+
code = IronWorkerNG::Code::Ruby.new(exec: @worker)
|
|
52
|
+
code.name(worker_name)
|
|
53
|
+
code.gem("iron_response")
|
|
54
|
+
@client.codes.create(code)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/test/rdd_test.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class RddTest < MiniTest::Unit::TestCase
|
|
4
|
+
def test_readme
|
|
5
|
+
|
|
6
|
+
config = Configuration.keys
|
|
7
|
+
batch = IronResponse::Batch.new
|
|
8
|
+
|
|
9
|
+
batch.auto_update_worker = true
|
|
10
|
+
batch.config[:iron_io] = config[:iron_io]
|
|
11
|
+
batch.config[:aws_s3] = config[:aws_s3]
|
|
12
|
+
batch.worker = "test/workers/is_prime.rb"
|
|
13
|
+
batch.params_array = Array(1..10).map {|i| {number: i}}
|
|
14
|
+
|
|
15
|
+
results = batch.run!
|
|
16
|
+
|
|
17
|
+
p results
|
|
18
|
+
assert_equal Array, results.class
|
|
19
|
+
end
|
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: iron_response
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Alan deLevie
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: iron_worker_ng
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: minitest
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 4.7.3
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 4.7.3
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: pry
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
description: Provides a response object for IronWorker tasks.
|
|
63
|
+
email:
|
|
64
|
+
- adelevie@gmail.com
|
|
65
|
+
executables: []
|
|
66
|
+
extensions: []
|
|
67
|
+
extra_rdoc_files: []
|
|
68
|
+
files:
|
|
69
|
+
- .gitignore
|
|
70
|
+
- Gemfile
|
|
71
|
+
- LICENSE
|
|
72
|
+
- README.md
|
|
73
|
+
- Rakefile
|
|
74
|
+
- iron_response.gemspec
|
|
75
|
+
- lib/iron_response.rb
|
|
76
|
+
- lib/iron_response/version.rb
|
|
77
|
+
- test/configuration.rb.example
|
|
78
|
+
- test/rdd_test.rb
|
|
79
|
+
- test/test_helper.rb
|
|
80
|
+
- test/workers/is_prime.rb
|
|
81
|
+
homepage: ''
|
|
82
|
+
licenses: []
|
|
83
|
+
post_install_message:
|
|
84
|
+
rdoc_options: []
|
|
85
|
+
require_paths:
|
|
86
|
+
- lib
|
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
|
+
none: false
|
|
89
|
+
requirements:
|
|
90
|
+
- - ! '>='
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
+
none: false
|
|
95
|
+
requirements:
|
|
96
|
+
- - ! '>='
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '0'
|
|
99
|
+
requirements: []
|
|
100
|
+
rubyforge_project:
|
|
101
|
+
rubygems_version: 1.8.24
|
|
102
|
+
signing_key:
|
|
103
|
+
specification_version: 3
|
|
104
|
+
summary: Provides a response object for IronWorker tasks.
|
|
105
|
+
test_files:
|
|
106
|
+
- test/configuration.rb.example
|
|
107
|
+
- test/rdd_test.rb
|
|
108
|
+
- test/test_helper.rb
|
|
109
|
+
- test/workers/is_prime.rb
|
|
110
|
+
has_rdoc:
|