iron_worker_ng 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/bin/iron_worker_ng +84 -10
- data/lib/iron_worker_ng/client.rb +12 -2
- data/lib/iron_worker_ng/code/ruby.rb +12 -5
- metadata +14 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/iron_worker_ng
CHANGED
@@ -4,9 +4,9 @@ require 'optparse'
|
|
4
4
|
require 'time'
|
5
5
|
require 'iron_worker_ng'
|
6
6
|
|
7
|
-
if $*.size == 0 || (not ['
|
7
|
+
if $*.size == 0 || (not ['codes.create', 'tasks.create', 'schedules.create', 'tasks.log'].include?($*[0]))
|
8
8
|
puts 'usage: iron_worker_ng COMMAND [OPTIONS]'
|
9
|
-
puts ' COMMAND:
|
9
|
+
puts ' COMMAND: codes.create, tasks.create, schedules.create, tasks.log'
|
10
10
|
puts ' run iron_worker_ng COMMAND --help to get more information about each command'
|
11
11
|
exit 1
|
12
12
|
end
|
@@ -21,7 +21,7 @@ end
|
|
21
21
|
|
22
22
|
client = IronWorkerNG::Client.new(ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'])
|
23
23
|
|
24
|
-
if command == '
|
24
|
+
if command == 'codes.create'
|
25
25
|
runtimes = IronWorkerNG::Code::Base.registered_types
|
26
26
|
runtimes_help = runtimes[0][:name] + ' (default)' + (runtimes.size == 1 ? '' : ', ') + runtimes.map { |r| r[:name] }[1 .. -1].join(', ')
|
27
27
|
|
@@ -32,7 +32,7 @@ if command == 'upload'
|
|
32
32
|
execute_features = []
|
33
33
|
|
34
34
|
opts = OptionParser.new do |opts|
|
35
|
-
opts.banner =
|
35
|
+
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
|
36
36
|
|
37
37
|
opts.on('-r', '--runtime RUNTIME', runtimes.map { |r| r[:name] }, "#{runtimes_help}") do |v|
|
38
38
|
runtime = v
|
@@ -76,7 +76,7 @@ if command == 'upload'
|
|
76
76
|
end
|
77
77
|
|
78
78
|
client.codes.create(code)
|
79
|
-
elsif command == '
|
79
|
+
elsif command == 'tasks.create' || command == 'schedules.create'
|
80
80
|
name = nil
|
81
81
|
params = {}
|
82
82
|
|
@@ -89,6 +89,8 @@ elsif command == 'queue' || command == 'schedule'
|
|
89
89
|
run_times = nil
|
90
90
|
run_every = nil
|
91
91
|
|
92
|
+
print_id = false
|
93
|
+
|
92
94
|
opts = OptionParser.new do |opts|
|
93
95
|
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
|
94
96
|
|
@@ -112,7 +114,7 @@ elsif command == 'queue' || command == 'schedule'
|
|
112
114
|
delay = v
|
113
115
|
end
|
114
116
|
|
115
|
-
if command == '
|
117
|
+
if command == 'schedules.create'
|
116
118
|
opts.on('--start-at TIME', 'start task at specified time') do |v|
|
117
119
|
start_at = Time.parse(v)
|
118
120
|
end
|
@@ -129,6 +131,10 @@ elsif command == 'queue' || command == 'schedule'
|
|
129
131
|
run_every = v
|
130
132
|
end
|
131
133
|
end
|
134
|
+
|
135
|
+
opts.on('--print-id', 'prints result id') do |v|
|
136
|
+
print_id = true
|
137
|
+
end
|
132
138
|
end
|
133
139
|
|
134
140
|
begin
|
@@ -149,16 +155,84 @@ elsif command == 'queue' || command == 'schedule'
|
|
149
155
|
options[:timeout] = timeout unless timeout.nil?
|
150
156
|
options[:delay] = delay unless delay.nil?
|
151
157
|
|
152
|
-
if command == '
|
158
|
+
if command == 'schedules.create'
|
153
159
|
options[:start_at] = start_at unless start_at.nil?
|
154
160
|
options[:end_at] = end_at unless end_at.nil?
|
155
161
|
options[:run_times] = run_times unless run_times.nil?
|
156
162
|
options[:run_every] = run_every unless run_every.nil?
|
157
163
|
end
|
158
164
|
|
159
|
-
|
160
|
-
|
165
|
+
id = nil
|
166
|
+
|
167
|
+
if command == 'tasks.create'
|
168
|
+
id = client.tasks.create(name, params, options).id
|
161
169
|
else
|
162
|
-
client.schedules.create(name, params, options)
|
170
|
+
id = client.schedules.create(name, params, options).id
|
171
|
+
end
|
172
|
+
|
173
|
+
print id if print_id
|
174
|
+
elsif command == 'tasks.log'
|
175
|
+
task_id = nil
|
176
|
+
live = false
|
177
|
+
|
178
|
+
opts = OptionParser.new do |opts|
|
179
|
+
opts.banner = "usage: iron_worker_ng #{command} [OPTIONS]"
|
180
|
+
|
181
|
+
opts.on('-t --task-id ID', 'task id') do |v|
|
182
|
+
task_id = v
|
183
|
+
end
|
184
|
+
|
185
|
+
#opts.on('--live', 'live log session') do |v|
|
186
|
+
# live = true
|
187
|
+
#end
|
188
|
+
end
|
189
|
+
|
190
|
+
begin
|
191
|
+
opts.parse!
|
192
|
+
rescue OptionParser::ParseError
|
193
|
+
puts $!.to_s
|
194
|
+
exit 1
|
195
|
+
end
|
196
|
+
|
197
|
+
if task_id.nil?
|
198
|
+
puts opts
|
199
|
+
exit 1
|
200
|
+
end
|
201
|
+
|
202
|
+
log = ''
|
203
|
+
if live
|
204
|
+
begin
|
205
|
+
log = client.tasks.log(task_id)
|
206
|
+
rescue IronWorkerNG::APIClientError
|
207
|
+
end
|
208
|
+
else
|
209
|
+
log = client.tasks.log(task_id)
|
210
|
+
end
|
211
|
+
|
212
|
+
print log
|
213
|
+
|
214
|
+
if live
|
215
|
+
status = client.tasks.get(task_id).status
|
216
|
+
|
217
|
+
while status == 'queued' || status == 'running'
|
218
|
+
if status == 'running'
|
219
|
+
begin
|
220
|
+
next_log = client.tasks.log(task_id)
|
221
|
+
print next_log[log.length .. - 1]
|
222
|
+
log = next_log
|
223
|
+
rescue IronWorkerNG::APIClientError
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
sleep 1
|
228
|
+
|
229
|
+
status = client.tasks.get(task_id).status
|
230
|
+
end
|
231
|
+
|
232
|
+
begin
|
233
|
+
next_log = client.tasks.log(task_id)
|
234
|
+
print next_log[log.length .. - 1]
|
235
|
+
rescue IronWorkerNG::APIClientError
|
236
|
+
end
|
163
237
|
end
|
164
238
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
require_relative 'api_client'
|
2
4
|
|
3
5
|
module IronWorkerNG
|
@@ -40,16 +42,24 @@ module IronWorkerNG
|
|
40
42
|
true
|
41
43
|
end
|
42
44
|
|
45
|
+
def tasks_get(task_id)
|
46
|
+
OpenStruct.new(@api.tasks_get(task_id))
|
47
|
+
end
|
48
|
+
|
43
49
|
def tasks_create(code_name, params = {}, options = {})
|
44
50
|
res = @api.tasks_create(code_name, {:project_id => @api.project_id, :token => @api.token, :params => params}.to_json, options)
|
45
51
|
|
46
|
-
res['tasks'][0]
|
52
|
+
OpenStruct.new(res['tasks'][0])
|
53
|
+
end
|
54
|
+
|
55
|
+
def tasks_log(task_id)
|
56
|
+
@api.tasks_log(task_id)
|
47
57
|
end
|
48
58
|
|
49
59
|
def schedules_create(code_name, params = {}, options = {})
|
50
60
|
res = @api.schedules_create(code_name, {:project_id => @api.project_id, :token => @api.token, :params => params}.to_json, options)
|
51
61
|
|
52
|
-
res['schedules'][0]
|
62
|
+
OpenStruct.new(res['schedules'][0])
|
53
63
|
end
|
54
64
|
end
|
55
65
|
end
|
@@ -35,12 +35,19 @@ end
|
|
35
35
|
|
36
36
|
require 'json'
|
37
37
|
|
38
|
-
payload = JSON.load(File.open(payload_file))
|
39
|
-
|
40
|
-
@iron_io_token = payload['token']
|
41
|
-
@iron_io_project_id = payload['project_id']
|
42
38
|
@iron_worker_task_id = task_id
|
43
|
-
|
39
|
+
|
40
|
+
@payload = File.read(payload_file)
|
41
|
+
|
42
|
+
parsed_payload = {}
|
43
|
+
begin
|
44
|
+
parsed_payload = JSON.parse(@payload)
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
|
48
|
+
@iron_io_token = parsed_payload['token']
|
49
|
+
@iron_io_project_id = parsed_payload['project_id']
|
50
|
+
@params = parsed_payload['params'] || {}
|
44
51
|
|
45
52
|
require worker_file_name
|
46
53
|
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-02-23 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|
17
|
-
requirement: &
|
17
|
+
requirement: &83479100 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *83479100
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rest-client
|
28
|
-
requirement: &
|
28
|
+
requirement: &83478800 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *83478800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rest
|
39
|
-
requirement: &
|
39
|
+
requirement: &83302470 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *83302470
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: json
|
50
|
-
requirement: &
|
50
|
+
requirement: &83301960 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *83301960
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: bundler
|
61
|
-
requirement: &
|
61
|
+
requirement: &83301580 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 1.0.0
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *83301580
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: jeweler
|
72
|
-
requirement: &
|
72
|
+
requirement: &83301220 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: 1.8.3
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *83301220
|
81
81
|
description: New generation ruby client for IronWorker
|
82
82
|
email: info@iron.io
|
83
83
|
executables:
|
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash:
|
126
|
+
hash: -801788643
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|