iron_worker_ng 0.16.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/bin/iron_worker +39 -1
- data/lib/iron_worker_ng/api_client.rb +7 -1
- data/lib/iron_worker_ng/cli.rb +20 -1
- data/lib/iron_worker_ng/client.rb +94 -1
- data/lib/iron_worker_ng/code/runtime/ruby.rb +2 -2
- data/lib/iron_worker_ng/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d161b8b3f520612288c567abcaf8c7de5c439bdb
|
4
|
+
data.tar.gz: 991e6a67ddfdfe01772203ad952e535ae65fbafe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 291b78dc0e3c213473fded9d559610fbbff74d256b26229bb990f6db1c727c0a6d64dc3b071030a2e5b86dbebe8cd8e1ef3fcfc096a3ff321b06625d26d01ca5
|
7
|
+
data.tar.gz: 41654a46d1e1901777b1442676cadc7744e04a9e9b41e0180be74fe18f89cb678c96867fdae4c1de60d4cdb10aefd888e873deea166cbde0d0652b82752443c5
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ All output to `STDOUT` will be logged and available for your review when your wo
|
|
35
35
|
# Creating The Code Package
|
36
36
|
|
37
37
|
Before you can run use IronWorker, be sure you've [created a free account with Iron.io](http://www.iron.io)
|
38
|
-
and [setup your Iron.io credentials on your system](http://dev.iron.io/
|
38
|
+
and [setup your Iron.io credentials on your system](http://dev.iron.io/worker/reference/configuration/) (either in a json
|
39
39
|
file or using ENV variables). You only need to do that once for your machine. If you've done that, then you can continue.
|
40
40
|
|
41
41
|
Since our worker will be executed in the cloud, you'll need to bundle all the necessary gems,
|
@@ -68,6 +68,10 @@ Use the `-p` parameter to pass in a payload:
|
|
68
68
|
|
69
69
|
iron_worker queue hello -p "{\"hi\": \"world\"}"
|
70
70
|
|
71
|
+
Use the `--wait` parameter to queue a task, wait for it to complete and print the log.
|
72
|
+
|
73
|
+
iron_worker queue hello -p "{\"hi\": \"world\"}" --wait
|
74
|
+
|
71
75
|
Most commonly you'll be queuing up tasks from code though, so you can do this:
|
72
76
|
|
73
77
|
```ruby
|
@@ -78,6 +82,18 @@ client = IronWorkerNG::Client.new
|
|
78
82
|
end
|
79
83
|
```
|
80
84
|
|
85
|
+
## Get task status
|
86
|
+
|
87
|
+
When you call `iron_worker queue X`, you'll see the task ID in the output which you can use to get the status.
|
88
|
+
|
89
|
+
iron_worker info task 5032f7360a4681382838e082
|
90
|
+
|
91
|
+
## Get task log
|
92
|
+
|
93
|
+
Similar to getting status, get the task ID in the queue command output, then:
|
94
|
+
|
95
|
+
iron_worker log 5032f7360a4681382838e082 --wait
|
96
|
+
|
81
97
|
## Retry a Task
|
82
98
|
|
83
99
|
You can retry task by id using same payload and options:
|
data/bin/iron_worker
CHANGED
@@ -30,6 +30,10 @@ def common_opts(opts)
|
|
30
30
|
opts.on('--project-id PROJECT_ID', 'project id') do |v|
|
31
31
|
@cli.project_id = v
|
32
32
|
end
|
33
|
+
|
34
|
+
opts.on('--token TOKEN', 'token') do |v|
|
35
|
+
@cli.token = v
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
|
@@ -37,7 +41,7 @@ if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
|
|
37
41
|
exit 0
|
38
42
|
end
|
39
43
|
|
40
|
-
commands = ['upload', 'queue', 'retry', 'schedule', 'log', 'run', 'install', 'webhook', 'info']
|
44
|
+
commands = ['upload', 'patch', 'queue', 'retry', 'schedule', 'log', 'run', 'install', 'webhook', 'info']
|
41
45
|
|
42
46
|
if $*.size == 0 || (not commands.include?($*[0]))
|
43
47
|
puts 'usage: iron_worker COMMAND [OPTIONS]'
|
@@ -110,6 +114,40 @@ if command == 'upload'
|
|
110
114
|
end
|
111
115
|
|
112
116
|
@cli.upload($*[0], params, options)
|
117
|
+
elsif command == 'patch'
|
118
|
+
params = {}
|
119
|
+
options = {}
|
120
|
+
|
121
|
+
opts = OptionParser.new do |opts|
|
122
|
+
opts.banner = "usage: iron_worker patch CODE_PACKAGE_NAME [OPTIONS]"
|
123
|
+
|
124
|
+
opts.on('-p', '--patch PATCH', 'patch file') do |v|
|
125
|
+
options[:patch] = v
|
126
|
+
end
|
127
|
+
|
128
|
+
common_opts(opts)
|
129
|
+
end
|
130
|
+
|
131
|
+
begin
|
132
|
+
opts.parse!
|
133
|
+
rescue OptionParser::ParseError
|
134
|
+
puts $!.to_s
|
135
|
+
exit 1
|
136
|
+
end
|
137
|
+
|
138
|
+
unless $*.size == 1
|
139
|
+
puts 'Please specify code package name'
|
140
|
+
puts opts
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
|
144
|
+
if options[:patch].nil?
|
145
|
+
puts 'Please specify patch'
|
146
|
+
puts opts
|
147
|
+
exit 1
|
148
|
+
end
|
149
|
+
|
150
|
+
@cli.patch($*[0], params, options)
|
113
151
|
elsif command == 'queue' || command == 'schedule'
|
114
152
|
params = {}
|
115
153
|
options = {}
|
@@ -83,7 +83,13 @@ module IronWorkerNG
|
|
83
83
|
|
84
84
|
def tasks_log(id)
|
85
85
|
check_id(id)
|
86
|
-
|
86
|
+
if block_given?
|
87
|
+
stream_get("projects/#{@project_id}/tasks/#{id}/log") do |chunk|
|
88
|
+
yield chunk
|
89
|
+
end
|
90
|
+
else
|
91
|
+
parse_response(get("projects/#{@project_id}/tasks/#{id}/log"), false)
|
92
|
+
end
|
87
93
|
end
|
88
94
|
|
89
95
|
def tasks_set_progress(id, options = {})
|
data/lib/iron_worker_ng/cli.rb
CHANGED
@@ -9,6 +9,7 @@ module IronWorkerNG
|
|
9
9
|
@config = nil
|
10
10
|
@env = nil
|
11
11
|
@project_id = nil
|
12
|
+
@token = nil
|
12
13
|
end
|
13
14
|
|
14
15
|
def beta?
|
@@ -35,6 +36,12 @@ module IronWorkerNG
|
|
35
36
|
@project_id = project_id
|
36
37
|
end
|
37
38
|
|
39
|
+
def token=(token)
|
40
|
+
@client = nil
|
41
|
+
|
42
|
+
@token = token
|
43
|
+
end
|
44
|
+
|
38
45
|
def log(msg)
|
39
46
|
IronCore::Logger.info 'IronWorkerNG', msg
|
40
47
|
end
|
@@ -47,7 +54,7 @@ module IronWorkerNG
|
|
47
54
|
if @client.nil?
|
48
55
|
log_group "Creating client"
|
49
56
|
|
50
|
-
@client = IronWorkerNG::Client.new(:config => @config, :env => @env, :project_id => @project_id)
|
57
|
+
@client = IronWorkerNG::Client.new(:config => @config, :env => @env, :project_id => @project_id, :token => @token)
|
51
58
|
|
52
59
|
project = client.projects.get
|
53
60
|
|
@@ -100,6 +107,18 @@ module IronWorkerNG
|
|
100
107
|
end
|
101
108
|
end
|
102
109
|
|
110
|
+
def patch(name, params, options)
|
111
|
+
client
|
112
|
+
|
113
|
+
log_group "Patching code package '#{name}'"
|
114
|
+
|
115
|
+
code_id = client.codes.patch(name, options)._id
|
116
|
+
code_info = client.codes.get(code_id)
|
117
|
+
|
118
|
+
log "Patched code package uploaded with id='#{code_id}' and revision='#{code_info.rev}'"
|
119
|
+
log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code_id}' for more info"
|
120
|
+
end
|
121
|
+
|
103
122
|
def queue(name, params, options)
|
104
123
|
client
|
105
124
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'base64'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
3
5
|
|
4
6
|
require 'iron_worker_ng/api_client'
|
5
7
|
|
@@ -153,6 +155,93 @@ module IronWorkerNG
|
|
153
155
|
OpenStruct.new(res)
|
154
156
|
end
|
155
157
|
|
158
|
+
def codes_patch(name, options = {})
|
159
|
+
IronCore::Logger.debug 'IronWorkerNG', "Calling codes.patch with name='#{name}' and options='#{options.to_s}'"
|
160
|
+
|
161
|
+
code = codes.list(:all => true).find { |c| c.name == name }
|
162
|
+
|
163
|
+
if code.nil?
|
164
|
+
IronCore::Logger.error 'IronWorkerNG', "Can't find code with name='#{name}' to patch", IronCore::Error
|
165
|
+
end
|
166
|
+
|
167
|
+
patcher_code_name = name + (name[0 .. 0].upcase == name[0 .. 0] ? '::Patcher' : '::patcher')
|
168
|
+
|
169
|
+
exec_dir = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'exec')
|
170
|
+
exec_file_name = exec_dir + '/patchcer.rb'
|
171
|
+
|
172
|
+
FileUtils.mkdir_p(exec_dir)
|
173
|
+
|
174
|
+
exec_file = File.open(exec_file_name, 'w')
|
175
|
+
exec_file.write <<EXEC_FILE
|
176
|
+
# #{IronWorkerNG.full_version}
|
177
|
+
|
178
|
+
File.open('.gemrc', 'w') do |gemrc|
|
179
|
+
gemrc.puts('gem: --no-ri --no-rdoc')
|
180
|
+
end
|
181
|
+
|
182
|
+
`gem install iron_worker_ng`
|
183
|
+
|
184
|
+
require 'iron_worker_ng'
|
185
|
+
|
186
|
+
client = IronWorkerNG::Client.new(JSON.parse(params[:client_options]))
|
187
|
+
|
188
|
+
original_code = client.codes.get(params[:code_id])
|
189
|
+
original_code_data = client.codes.download(params[:code_id])
|
190
|
+
|
191
|
+
`mkdir code`
|
192
|
+
original_code_zip = File.open('code/code.zip', 'w')
|
193
|
+
original_code_zip.write(original_code_data)
|
194
|
+
original_code_zip.close
|
195
|
+
`cd code && unzip code.zip && rm code.zip && cd ..`
|
196
|
+
|
197
|
+
patch_file = Dir['patch/*'].first
|
198
|
+
|
199
|
+
system("cd code && patch -fp1 <../\#{patch_file} && cd ..") || exit(1)
|
200
|
+
|
201
|
+
code_container = IronWorkerNG::Code::Container::Zip.new
|
202
|
+
|
203
|
+
Dir['code/*'].each do |entry|
|
204
|
+
code_container.add(entry[5 .. -1], entry)
|
205
|
+
end
|
206
|
+
|
207
|
+
code_container.close
|
208
|
+
|
209
|
+
res = client.api.codes_create(original_code.name, code_container.name, 'sh', '__runner__.sh', :config => original_code.config)
|
210
|
+
|
211
|
+
res['_id'] = res['id']
|
212
|
+
res = OpenStruct.new(res)
|
213
|
+
|
214
|
+
client.tasks.set_progress(iron_task_id, :msg => res.marshal_dump.to_json)
|
215
|
+
EXEC_FILE
|
216
|
+
exec_file.close
|
217
|
+
|
218
|
+
patcher_code = IronWorkerNG::Code::Base.new
|
219
|
+
patcher_code.runtime = :ruby
|
220
|
+
patcher_code.name = patcher_code_name
|
221
|
+
patcher_code.exec(exec_file_name)
|
222
|
+
patcher_code.file(options[:patch], 'patch')
|
223
|
+
|
224
|
+
patcher_container_file = patcher_code.create_container
|
225
|
+
|
226
|
+
@api.codes_create(patcher_code_name, patcher_container_file, 'sh', '__runner__.sh', {})
|
227
|
+
|
228
|
+
FileUtils.rm_rf(exec_dir)
|
229
|
+
File.unlink(patcher_container_file)
|
230
|
+
|
231
|
+
patcher_task = tasks.create(patcher_code_name, :code_id => code._id, :client_options => @api.options.to_json)
|
232
|
+
|
233
|
+
patcher_task = tasks.wait_for(patcher_task._id)
|
234
|
+
|
235
|
+
if patcher_task.status != 'complete'
|
236
|
+
log = tasks.log(patcher_task._id)
|
237
|
+
IronCore::Logger.error 'IronWorkerNG', "Error while patching worker\n" + log, IronCore::Error
|
238
|
+
end
|
239
|
+
|
240
|
+
res = JSON.parse(patcher_task.msg)
|
241
|
+
res['_id'] = res['id']
|
242
|
+
OpenStruct.new(res)
|
243
|
+
end
|
244
|
+
|
156
245
|
def codes_delete(code_id)
|
157
246
|
IronCore::Logger.debug 'IronWorkerNG', "Calling codes.delete with code_id='#{code_id}'"
|
158
247
|
|
@@ -226,7 +315,11 @@ module IronWorkerNG
|
|
226
315
|
def tasks_log(task_id)
|
227
316
|
IronCore::Logger.debug 'IronWorkerNG', "Calling tasks.log with task_id='#{task_id}'"
|
228
317
|
|
229
|
-
|
318
|
+
if block_given?
|
319
|
+
@api.tasks_log(task_id) { |chunk| yield(chunk) }
|
320
|
+
else
|
321
|
+
@api.tasks_log(task_id)
|
322
|
+
end
|
230
323
|
end
|
231
324
|
|
232
325
|
def tasks_set_progress(task_id, options = {})
|
@@ -40,8 +40,8 @@ task_id = nil
|
|
40
40
|
task_id = $*[i + 1] if $*[i] == '-id'
|
41
41
|
end
|
42
42
|
|
43
|
-
ENV['GEM_PATH'] = ([root
|
44
|
-
ENV['GEM_HOME'] = root
|
43
|
+
ENV['GEM_PATH'] = ([File.join(root, '__gems__')] + Gem.path).join(':')
|
44
|
+
ENV['GEM_HOME'] = File.join(root, '__gems__')
|
45
45
|
|
46
46
|
$:.unshift("\#{root}")
|
47
47
|
|
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kirilenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iron_core
|
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
238
|
version: 1.3.6
|
239
239
|
requirements: []
|
240
240
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.0.
|
241
|
+
rubygems_version: 2.0.3
|
242
242
|
signing_key:
|
243
243
|
specification_version: 4
|
244
244
|
summary: New generation ruby client for IronWorker
|