iron_worker_ng 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/{iron_worker_ng → iron_worker} +5 -5
- data/lib/iron_worker_ng/api_client.rb +41 -22
- data/lib/iron_worker_ng/client.rb +4 -1
- data/lib/iron_worker_ng/code/base.rb +8 -4
- data/lib/iron_worker_ng/code/ruby.rb +2 -17
- metadata +5 -21
- data/examples/ruby/hello/hello.rb +0 -26
- data/examples/ruby/hello/hello_worker.rb +0 -1
- data/examples/ruby/master_slave/master_slave.rb +0 -39
- data/examples/ruby/master_slave/master_worker.rb +0 -22
- data/examples/ruby/master_slave/slave_worker.rb +0 -1
- data/examples/ruby/simple/Gemfile +0 -5
- data/examples/ruby/simple/sample_worker.rb +0 -3
- data/examples/ruby/simple/simple.rb +0 -66
- data/test/Gemfile +0 -5
- data/test/Rakefile +0 -45
- data/test/data/dir1/stub +0 -0
- data/test/data/dir2/test +0 -1
- data/test/hello.rb +0 -1
- data/test/helpers.rb +0 -46
- data/test/test_basic.rb +0 -13
- data/test/test_common_features.rb +0 -86
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -5,9 +5,9 @@ require 'time'
|
|
5
5
|
require 'iron_worker_ng'
|
6
6
|
|
7
7
|
if $*.size == 0 || (not ['codes.create', 'tasks.create', 'schedules.create', 'tasks.log'].include?($*[0]))
|
8
|
-
puts 'usage:
|
8
|
+
puts 'usage: iron_worker COMMAND [OPTIONS]'
|
9
9
|
puts ' COMMAND: codes.create, tasks.create, schedules.create, tasks.log'
|
10
|
-
puts ' run
|
10
|
+
puts ' run iron_worker COMMAND --help to get more information about each command'
|
11
11
|
exit 1
|
12
12
|
end
|
13
13
|
|
@@ -27,7 +27,7 @@ if command == 'codes.create'
|
|
27
27
|
execute_features = []
|
28
28
|
|
29
29
|
opts = OptionParser.new do |opts|
|
30
|
-
opts.banner = "usage:
|
30
|
+
opts.banner = "usage: iron_worker #{command} [OPTIONS]"
|
31
31
|
|
32
32
|
opts.on('-r', '--runtime RUNTIME', runtimes.map { |r| r[:name] }, "#{runtimes_help}") do |v|
|
33
33
|
runtime = v
|
@@ -87,7 +87,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
|
|
87
87
|
print_id = false
|
88
88
|
|
89
89
|
opts = OptionParser.new do |opts|
|
90
|
-
opts.banner = "usage:
|
90
|
+
opts.banner = "usage: iron_worker #{command} [OPTIONS]"
|
91
91
|
|
92
92
|
opts.on('-n', '--name NAME', 'code name') do |v|
|
93
93
|
name = v
|
@@ -171,7 +171,7 @@ elsif command == 'tasks.log'
|
|
171
171
|
live = false
|
172
172
|
|
173
173
|
opts = OptionParser.new do |opts|
|
174
|
-
opts.banner = "usage:
|
174
|
+
opts.banner = "usage: iron_worker #{command} [OPTIONS]"
|
175
175
|
|
176
176
|
opts.on('-t --task-id ID', 'task id') do |v|
|
177
177
|
task_id = v
|
@@ -20,32 +20,33 @@ module IronWorkerNG
|
|
20
20
|
|
21
21
|
def initialize(options = {})
|
22
22
|
@token = options[:token] || options['token']
|
23
|
-
@token ||= ENV['IRON_IO_TOKEN']
|
24
|
-
@token ||= ENV['IRON_TOKEN']
|
25
|
-
|
26
23
|
@project_id = options[:project_id] || options['project_id']
|
27
|
-
|
24
|
+
|
25
|
+
if (@token.nil? || @project_id.nil?) && ((not options[:yaml_config_file].nil?) || (not options['yaml_config_file'].nil?))
|
26
|
+
load_yaml_config(options[:yaml_config_file] || options['yaml_config_file'])
|
27
|
+
end
|
28
|
+
|
29
|
+
if (@token.nil? || @project_id.nil?) && ((not options[:json_config_file].nil?) || (not options['json_config_file'].nil?))
|
30
|
+
load_json_config(options[:json_config_file] || options['json_config_file'])
|
31
|
+
end
|
32
|
+
|
33
|
+
if @token.nil? || @project_id.nil?
|
34
|
+
load_yaml_config('iron.yml')
|
35
|
+
end
|
36
|
+
|
37
|
+
if @token.nil? || @project_id.nil?
|
38
|
+
load_json_config('iron.json')
|
39
|
+
end
|
40
|
+
|
41
|
+
@token ||= ENV['IRON_TOKEN']
|
28
42
|
@project_id ||= ENV['IRON_PROJECT_ID']
|
29
43
|
|
30
44
|
if @token.nil? || @project_id.nil?
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@token ||= config['iron_io']['token']
|
37
|
-
@project_id ||= config['iron_io']['project_id']
|
38
|
-
end
|
39
|
-
|
40
|
-
unless config['iron'].nil?
|
41
|
-
@token ||= config['iron']['token']
|
42
|
-
@project_id ||= config['iron']['project_id']
|
43
|
-
end
|
44
|
-
|
45
|
-
@token ||= config['token']
|
46
|
-
@project_id ||= config['project_id']
|
47
|
-
end
|
48
|
-
end
|
45
|
+
load_yaml_config('~/.iron.yml')
|
46
|
+
end
|
47
|
+
|
48
|
+
if @token.nil? || @project_id.nil?
|
49
|
+
load_json_config('~/.iron.json')
|
49
50
|
end
|
50
51
|
|
51
52
|
if (not @token) || (not @project_id)
|
@@ -64,6 +65,24 @@ module IronWorkerNG
|
|
64
65
|
@rest = Rest::Client.new
|
65
66
|
end
|
66
67
|
|
68
|
+
def load_yaml_config(config_file)
|
69
|
+
if File.exists?(File.expand_path(config_file))
|
70
|
+
config = YAML.load_file(File.expand_path(config_file))
|
71
|
+
|
72
|
+
@token ||= config['token']
|
73
|
+
@project_id ||= config['project_id']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_json_config(config_file)
|
78
|
+
if File.exists?(File.expand_path(config_file))
|
79
|
+
config = JSON.load(File.read(File.expand_path(config_file)))
|
80
|
+
|
81
|
+
@token ||= config['token']
|
82
|
+
@project_id ||= config['project_id']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
67
86
|
def common_request_hash
|
68
87
|
{
|
69
88
|
'Content-Type' => 'application/json',
|
@@ -105,14 +105,17 @@ module IronWorkerNG
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def tasks_wait_for(task_id, options = {})
|
108
|
-
options[:sleep] ||= 5
|
108
|
+
options[:sleep] ||= options['sleep'] || 5
|
109
109
|
|
110
110
|
task = tasks_get(task_id)
|
111
|
+
|
111
112
|
while task.status == 'queued' || task.status == 'running'
|
112
113
|
yield task if block_given?
|
113
114
|
sleep options[:sleep]
|
114
115
|
task = tasks_get(task_id)
|
115
116
|
end
|
117
|
+
|
118
|
+
task
|
116
119
|
end
|
117
120
|
|
118
121
|
def schedules_list(options = {})
|
@@ -38,10 +38,6 @@ module IronWorkerNG
|
|
38
38
|
@name = nil
|
39
39
|
@features = []
|
40
40
|
|
41
|
-
if File.exists?('Workerfile')
|
42
|
-
eval(File.read('Workerfile'))
|
43
|
-
end
|
44
|
-
|
45
41
|
if args.length == 1 && args[0].class == String && File.exists?(args[0])
|
46
42
|
merge_exec(args[0])
|
47
43
|
elsif args.length == 1 && args[0].class == String
|
@@ -53,6 +49,14 @@ module IronWorkerNG
|
|
53
49
|
merge_exec(exec) unless exec.nil?
|
54
50
|
end
|
55
51
|
|
52
|
+
if args.length == 1 && args[0].class == Hash && ((not args[0][:workerfile].nil?) || (not args[0]['workerfile'].nil?))
|
53
|
+
eval(File.read(File.expand_path(args[0][:workerfile] || args[0]['workerfile'])))
|
54
|
+
else
|
55
|
+
if File.exists?('Workerfile')
|
56
|
+
eval(File.read('Workerfile'))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
56
60
|
unless block.nil?
|
57
61
|
instance_eval(&block)
|
58
62
|
end
|
@@ -41,7 +41,6 @@ $:.unshift("\#{root}")
|
|
41
41
|
|
42
42
|
require 'json'
|
43
43
|
|
44
|
-
@iron_worker_task_id = task_id
|
45
44
|
@iron_task_id = task_id
|
46
45
|
|
47
46
|
@payload = File.read(payload_file)
|
@@ -52,10 +51,8 @@ begin
|
|
52
51
|
rescue
|
53
52
|
end
|
54
53
|
|
55
|
-
@
|
56
|
-
@
|
57
|
-
@iron_io_project_id = parsed_payload['project_id'] || nil
|
58
|
-
@iron_project_id = @iron_io_project_id
|
54
|
+
@iron_token = parsed_payload['token'] || nil
|
55
|
+
@iron_project_id = parsed_payload['project_id'] || nil
|
59
56
|
@params = parsed_payload['params'] || {}
|
60
57
|
|
61
58
|
keys = @params.keys
|
@@ -67,26 +64,14 @@ def payload
|
|
67
64
|
@payload
|
68
65
|
end
|
69
66
|
|
70
|
-
def iron_worker_task_id
|
71
|
-
@iron_worker_task_id
|
72
|
-
end
|
73
|
-
|
74
67
|
def iron_task_id
|
75
68
|
@iron_task_id
|
76
69
|
end
|
77
70
|
|
78
|
-
def iron_io_token
|
79
|
-
@iron_io_token
|
80
|
-
end
|
81
|
-
|
82
71
|
def iron_token
|
83
72
|
@iron_token
|
84
73
|
end
|
85
74
|
|
86
|
-
def iron_io_project_id
|
87
|
-
@iron_io_project_id
|
88
|
-
end
|
89
|
-
|
90
75
|
def iron_project_id
|
91
76
|
@iron_project_id
|
92
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_worker_ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
description: New generation ruby client for IronWorker
|
112
112
|
email: info@iron.io
|
113
113
|
executables:
|
114
|
-
-
|
114
|
+
- iron_worker
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files:
|
117
117
|
- LICENSE
|
@@ -120,15 +120,7 @@ files:
|
|
120
120
|
- LICENSE
|
121
121
|
- README.md
|
122
122
|
- VERSION
|
123
|
-
- bin/
|
124
|
-
- examples/ruby/hello/hello.rb
|
125
|
-
- examples/ruby/hello/hello_worker.rb
|
126
|
-
- examples/ruby/master_slave/master_slave.rb
|
127
|
-
- examples/ruby/master_slave/master_worker.rb
|
128
|
-
- examples/ruby/master_slave/slave_worker.rb
|
129
|
-
- examples/ruby/simple/Gemfile
|
130
|
-
- examples/ruby/simple/sample_worker.rb
|
131
|
-
- examples/ruby/simple/simple.rb
|
123
|
+
- bin/iron_worker
|
132
124
|
- lib/iron_worker_ng.rb
|
133
125
|
- lib/iron_worker_ng/api_client.rb
|
134
126
|
- lib/iron_worker_ng/api_client_error.rb
|
@@ -150,14 +142,6 @@ files:
|
|
150
142
|
- lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
|
151
143
|
- lib/iron_worker_ng/logger.rb
|
152
144
|
- lib/iron_worker_ng/version.rb
|
153
|
-
- test/Gemfile
|
154
|
-
- test/Rakefile
|
155
|
-
- test/data/dir1/stub
|
156
|
-
- test/data/dir2/test
|
157
|
-
- test/hello.rb
|
158
|
-
- test/helpers.rb
|
159
|
-
- test/test_basic.rb
|
160
|
-
- test/test_common_features.rb
|
161
145
|
homepage: https://github.com/iron-io/iron_worker_ruby_ng
|
162
146
|
licenses: []
|
163
147
|
post_install_message:
|
@@ -172,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
156
|
version: '0'
|
173
157
|
segments:
|
174
158
|
- 0
|
175
|
-
hash: -
|
159
|
+
hash: -1067507039
|
176
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
161
|
none: false
|
178
162
|
requirements:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'iron_worker_ng'
|
2
|
-
|
3
|
-
# to run examples, you must specify iron.io authentication token and project id
|
4
|
-
token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
|
5
|
-
raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
|
6
|
-
"environment variables") unless token and project_id
|
7
|
-
|
8
|
-
# initializing api object with them
|
9
|
-
client = IronWorkerNG::Client.new(:token => token,
|
10
|
-
:project_id => project_id)
|
11
|
-
|
12
|
-
# create ruby code bundle
|
13
|
-
code = IronWorkerNG::Code::Ruby.new
|
14
|
-
code.merge_exec(File.dirname(__FILE__) + '/hello_worker.rb')
|
15
|
-
|
16
|
-
# upload it to iron.io
|
17
|
-
client.codes.create(code)
|
18
|
-
|
19
|
-
# create task to run the bundle
|
20
|
-
task_id = client.tasks.create('HelloWorker').id
|
21
|
-
|
22
|
-
# wait for the task to finish
|
23
|
-
client.tasks.wait_for(task_id)
|
24
|
-
|
25
|
-
# retriving task log
|
26
|
-
log = client.tasks.log(task_id) #> log == "hello\n" -- worker stdout is in log
|
@@ -1 +0,0 @@
|
|
1
|
-
puts "hello"
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'iron_worker_ng'
|
2
|
-
|
3
|
-
# to run examples, you must specify iron.io authentication token and project id
|
4
|
-
token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
|
5
|
-
raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
|
6
|
-
"environment variables") unless token and project_id
|
7
|
-
|
8
|
-
# initializing api object with them
|
9
|
-
client = IronWorkerNG::Client.new(:token => token,
|
10
|
-
:project_id => project_id)
|
11
|
-
|
12
|
-
# create master code bundle
|
13
|
-
master = IronWorkerNG::Code::Ruby.new
|
14
|
-
master.merge_exec(File.dirname(__FILE__) + '/master_worker.rb')
|
15
|
-
master.merge_gem('iron_worker_ng') # we need it to queue slave workers
|
16
|
-
|
17
|
-
# create slave code bundle
|
18
|
-
slave = IronWorkerNG::Code::Ruby.new
|
19
|
-
slave.merge_exec(File.dirname(__FILE__) + '/slave_worker.rb')
|
20
|
-
|
21
|
-
# upload both
|
22
|
-
client.codes.create(master)
|
23
|
-
client.codes.create(slave)
|
24
|
-
|
25
|
-
# run master task
|
26
|
-
task_id = client.tasks.create('MasterWorker',
|
27
|
-
{
|
28
|
-
:args => [ [1, 2, 3],
|
29
|
-
[4, 5, 6],
|
30
|
-
[7, 8, 9] ]
|
31
|
-
}).id
|
32
|
-
|
33
|
-
# wait for the task to finish
|
34
|
-
client.tasks.wait_for(task_id)
|
35
|
-
|
36
|
-
# retriving task log
|
37
|
-
log = client.tasks.log(task_id)
|
38
|
-
|
39
|
-
#> log.lines.find{ |l| l =~ /Sum =/ } == "Sum = 45\n" -- correct result in log
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'iron_worker_ng'
|
2
|
-
|
3
|
-
# token and project id are available inside worker
|
4
|
-
client = IronWorkerNG::Client.new(:token => iron_io_token,
|
5
|
-
:project_id => iron_io_project_id)
|
6
|
-
|
7
|
-
puts 'Running slave workers...'
|
8
|
-
task_ids = []
|
9
|
-
params[:args].each do |arg|
|
10
|
-
puts "Queueing slave with arg=#{arg.to_s}"
|
11
|
-
task_ids << client.tasks.create('SlaveWorker', { :arg => arg }).id
|
12
|
-
end
|
13
|
-
|
14
|
-
puts 'Retriving results from slaves logs'
|
15
|
-
results = task_ids.map do |id|
|
16
|
-
client.tasks.wait_for(id)
|
17
|
-
client.tasks.log(id).to_i
|
18
|
-
end
|
19
|
-
|
20
|
-
puts "Sum = #{ results.inject(:+) }"
|
21
|
-
|
22
|
-
puts 'Done'
|
@@ -1 +0,0 @@
|
|
1
|
-
puts params[:arg].inject(:+)
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'iron_worker_ng'
|
2
|
-
|
3
|
-
# to run examples, you must specify iron.io authentication token and project id
|
4
|
-
token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
|
5
|
-
raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
|
6
|
-
"environment variables") unless token and project_id
|
7
|
-
|
8
|
-
IronWorkerNG::Logger.logger.level = ::Logger::DEBUG
|
9
|
-
|
10
|
-
# initializing api object with them
|
11
|
-
client = IronWorkerNG::Client.new(:token => token,
|
12
|
-
:project_id => project_id,
|
13
|
-
# rest are optinal
|
14
|
-
:scheme => 'https',
|
15
|
-
:port => 443,
|
16
|
-
:api_version => 2,
|
17
|
-
:host => 'worker-aws-us-east-1.iron.io')
|
18
|
-
|
19
|
-
# creating code bundle
|
20
|
-
|
21
|
-
# if not specified, name default to worker name converted from underscore to camel style
|
22
|
-
code = IronWorkerNG::Code::Ruby.new
|
23
|
-
code.merge_exec('/sample_worker.rb')
|
24
|
-
#> code.name == 'SampleWorker'
|
25
|
-
|
26
|
-
# still can pass name in constructor
|
27
|
-
code = IronWorkerNG::Code::Ruby.new('transmogrify')
|
28
|
-
#> code.name == 'transmogrify'
|
29
|
-
code.merge_exec(File.dirname(__FILE__) + '/sample_worker.rb')
|
30
|
-
|
31
|
-
# once worker merged, following attempts will be ignored
|
32
|
-
code.merge_exec('anything')
|
33
|
-
#> code.worker.path.end_with? '/worker.rb'
|
34
|
-
|
35
|
-
# if worker requires some gems, we
|
36
|
-
|
37
|
-
# we can specify worker dependency on gem
|
38
|
-
code.merge_gem('jeweler')
|
39
|
-
# or on Gemfile, which is recommended
|
40
|
-
code.merge_gemfile(File.dirname(__FILE__) + '/Gemfile',
|
41
|
-
:default, :extra)
|
42
|
-
# all those dependencies will be resolved using bundler gem
|
43
|
-
|
44
|
-
# upload code bundle to iron.io
|
45
|
-
client.codes_create(code)
|
46
|
-
|
47
|
-
# we can retrive code packages list
|
48
|
-
codes = client.codes_list
|
49
|
-
#> codes.map{|c| c.name}.include?('transmogrify')
|
50
|
-
|
51
|
-
code_info = codes.find{|c| c.name == 'transmogrify'}
|
52
|
-
# other way to get such info is codes.get:
|
53
|
-
same_code_info = client.codes_get(code_info.id)
|
54
|
-
#> same_code_info == code_info
|
55
|
-
|
56
|
-
# create task to run the bundle
|
57
|
-
task_id = client.tasks_create('transmogrify').id
|
58
|
-
|
59
|
-
# wait for the task to finish
|
60
|
-
client.tasks_wait_for(task_id)
|
61
|
-
|
62
|
-
# retriving task log
|
63
|
-
log = client.tasks_log(task_id) #> log == "hello\n" -- worker stdout is in log
|
64
|
-
|
65
|
-
# cleanup
|
66
|
-
client.codes_delete(code_info.id)
|
data/test/Gemfile
DELETED
data/test/Rakefile
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
Dir.chdir(File.dirname(__FILE__) + '/..')
|
5
|
-
|
6
|
-
Rake::TestTask.new do |t|
|
7
|
-
examples_tests_dir = Dir.mktmpdir('iw_examples')
|
8
|
-
|
9
|
-
FileUtils::cp_r(Dir.glob('examples/*'), examples_tests_dir)
|
10
|
-
|
11
|
-
Dir.glob('examples/**/**.rb').each do |path|
|
12
|
-
next unless path =~ %r|examples/(.*)/([^/]+)/\2.rb$|
|
13
|
-
|
14
|
-
dir = $1
|
15
|
-
name = $2
|
16
|
-
|
17
|
-
test_path = examples_tests_dir + "/#{dir}/#{name}/test_example_#{name}.rb"
|
18
|
-
|
19
|
-
File.open(test_path, 'w') do |out|
|
20
|
-
out << "require 'helpers'\n"
|
21
|
-
out << "class #{name.capitalize}Test < Test::Unit::TestCase\n"
|
22
|
-
out << "def test_example\n"
|
23
|
-
|
24
|
-
File.readlines(path).each do |line|
|
25
|
-
line, assert_str = line.chomp.split /#>/
|
26
|
-
out << line << "\n"
|
27
|
-
|
28
|
-
if assert_str
|
29
|
-
cond, desc = assert_str.split /--/
|
30
|
-
out << "assert(" << cond << ", '" <<
|
31
|
-
(desc or "").gsub(/'/, "\\\\'") << "')\n"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
out << "end\nend\n"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
t.libs << "lib" << "test" << examples_tests_dir
|
40
|
-
files = FileList['test/**/**.rb',
|
41
|
-
examples_tests_dir + '/**/test_*.rb']
|
42
|
-
t.test_files = files.keep_if{ |f| f =~ Regexp.new(ENV['TESTP'] || '') }
|
43
|
-
|
44
|
-
t.verbose = true
|
45
|
-
end
|
data/test/data/dir1/stub
DELETED
File without changes
|
data/test/data/dir2/test
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
test
|
data/test/hello.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
puts "hello"
|
data/test/helpers.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
require './lib/iron_worker_ng.rb'
|
5
|
-
|
6
|
-
def code_bundle(name,&block)
|
7
|
-
code = IronWorkerNG::Code::Ruby.new(name)
|
8
|
-
|
9
|
-
class << code
|
10
|
-
def worker_code(str)
|
11
|
-
tmpdir = Dir.tmpdir + '/' + Digest::MD5.hexdigest(str)
|
12
|
-
Dir.mkdir tmpdir unless Dir.exist? tmpdir
|
13
|
-
|
14
|
-
tmpfname = tmpdir + '/worker.rb'
|
15
|
-
File.open(tmpfname, "w") { |f| f << str }
|
16
|
-
|
17
|
-
puts "created #{tmpfname}"
|
18
|
-
merge_worker(tmpfname)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
code.instance_eval(&block)
|
23
|
-
|
24
|
-
code
|
25
|
-
end
|
26
|
-
|
27
|
-
def inspect_zip(code)
|
28
|
-
zip_file = code.create_zip
|
29
|
-
yield Zip::ZipFile.open(zip_file)
|
30
|
-
File.unlink zip_file
|
31
|
-
end
|
32
|
-
|
33
|
-
class IWNGTest < Test::Unit::TestCase
|
34
|
-
attr_accessor :client
|
35
|
-
|
36
|
-
def setup
|
37
|
-
IronWorkerNG::Logger.logger.level = ::Logger::DEBUG
|
38
|
-
|
39
|
-
token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
|
40
|
-
raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
|
41
|
-
"environment variables") unless token and project_id
|
42
|
-
|
43
|
-
@client = IronWorkerNG::Client.new(:token => token,
|
44
|
-
:project_id => project_id )
|
45
|
-
end
|
46
|
-
end
|
data/test/test_basic.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'helpers'
|
2
|
-
|
3
|
-
class BasicTest < IWNGTest
|
4
|
-
def _test_basic
|
5
|
-
code = IronWorkerNG::Code::Ruby.new('test_basic')
|
6
|
-
code.merge_worker(File.dirname(__FILE__) + '/hello.rb')
|
7
|
-
client.codes_create(code)
|
8
|
-
task_id = client.tasks_create('test_basic').id
|
9
|
-
client.tasks_wait_for(task_id)
|
10
|
-
log = client.tasks_log(task_id)
|
11
|
-
assert_equal( "hello\n", log, "worker stdout is in log" )
|
12
|
-
end
|
13
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'helpers'
|
2
|
-
require 'zip/zip'
|
3
|
-
|
4
|
-
class CommonFeaturesTest < IWNGTest
|
5
|
-
|
6
|
-
def test_merge_file
|
7
|
-
code = code_bundle('test') do
|
8
|
-
merge_file('test', 'test/data/dir2')
|
9
|
-
merge_worker('test/hello.rb')
|
10
|
-
end
|
11
|
-
|
12
|
-
inspect_zip(code) do |zip|
|
13
|
-
assert zip.find_entry('test/data/dir2/test')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_merge_file_no_dest
|
18
|
-
code = code_bundle('test') do
|
19
|
-
merge_file('Gemfile')
|
20
|
-
merge_worker('test/hello.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
inspect_zip(code) do |zip|
|
24
|
-
assert zip.find_entry('Gemfile')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_merge_dir_check
|
29
|
-
assert_raise RuntimeError, "should check if merged dir exists" do
|
30
|
-
code_bundle('test') do
|
31
|
-
merge_dir('dir2', 'test/data')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_merge_dir
|
37
|
-
code = code_bundle('test') do
|
38
|
-
merge_dir('test/data/dir2', 'test/data')
|
39
|
-
merge_worker('test/hello.rb')
|
40
|
-
end
|
41
|
-
|
42
|
-
inspect_zip(code) do |zip|
|
43
|
-
assert zip.find_entry('test/data/dir2/test')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_merge_dir_no_dest
|
48
|
-
code = code_bundle('test') do
|
49
|
-
merge_dir('test')
|
50
|
-
merge_worker('test/hello.rb')
|
51
|
-
end
|
52
|
-
|
53
|
-
inspect_zip(code) do |zip|
|
54
|
-
assert zip.find_entry('test/hello.rb')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_symlinks
|
59
|
-
File.unlink 'test/data/dir1/dir2' if
|
60
|
-
File.symlink? 'test/data/dir1/dir2'
|
61
|
-
|
62
|
-
Dir.chdir('test/data/dir1') do
|
63
|
-
File.symlink('../dir2', 'dir2')
|
64
|
-
end
|
65
|
-
|
66
|
-
code = code_bundle 'test_symlinks' do
|
67
|
-
merge_dir('test/data/dir1', 'test/data')
|
68
|
-
merge_dir('test/data/dir2', 'test/data')
|
69
|
-
worker_code 'puts File.read("test/data/dir1/dir2/test")'
|
70
|
-
end
|
71
|
-
|
72
|
-
inspect_zip(code) do |zip|
|
73
|
-
assert_equal '../dir2', zip.read('test/data/dir1/dir2')
|
74
|
-
end
|
75
|
-
|
76
|
-
client.codes_create(code)
|
77
|
-
task_id = client.tasks_create('test_symlinks').id
|
78
|
-
client.tasks_wait_for(task_id)
|
79
|
-
log = client.tasks_log(task_id)
|
80
|
-
|
81
|
-
assert_equal "test", log
|
82
|
-
|
83
|
-
File.unlink 'test/data/dir1/dir2'
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|