iron_worker_ng 0.9.6 → 0.10.0

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/README.md CHANGED
@@ -48,7 +48,7 @@ runtime "ruby"
48
48
  exec "hello_worker.rb"
49
49
  ```
50
50
 
51
- You can read more about `.worker` files here: http://dev.iron.io/worker/reference/worker-files/
51
+ You can read more about `.worker` files here: http://dev.iron.io/worker/reference/dotworker/
52
52
 
53
53
  ## Uploading the Code Package
54
54
 
@@ -77,6 +77,19 @@ client = IronWorkerNG::Client.new
77
77
  client.tasks.create("hello", "foo"=>"bar")
78
78
  end
79
79
  ```
80
+
81
+ ## Retry a Task
82
+
83
+ You can retry task by id using same payload and options:
84
+
85
+ iron_worker retry 5032f7360a4681382838e082
86
+
87
+ or
88
+ ```ruby
89
+ client.tasks.retry('5032f7360a4681382838e082', :delay => 10)
90
+ ```
91
+
92
+
80
93
  ### Debugging
81
94
 
82
95
  To get a bunch of extra output to debug things, turn it on using:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.6
1
+ 0.10.0
data/bin/iron_worker CHANGED
@@ -4,28 +4,57 @@ require 'optparse'
4
4
  require 'time'
5
5
  require 'iron_worker_ng'
6
6
 
7
+ LOG_GROUP = '------> '
8
+ LOG_ENTRY = ' '
9
+
7
10
  class IronWorkerCLILoggerFormatter < ::Logger::Formatter
8
11
  def call(severity, time, proname, msg)
12
+ msg = LOG_ENTRY + msg unless msg.start_with?(LOG_GROUP)
9
13
  msg + "\n"
10
14
  end
11
15
  end
12
16
 
17
+ IronCore::Logger.logger.formatter = IronWorkerCLILoggerFormatter.new
18
+
19
+ def log(msg)
20
+ IronCore::Logger.info 'IronWorkerNG', msg
21
+ end
22
+
13
23
  @env = nil
24
+ @project_id = nil
14
25
 
15
26
  def create_client
16
- client = IronWorkerNG::Client.new(:env => @env)
27
+ log "#{LOG_GROUP}Detecting Configuration"
28
+
29
+ client = IronWorkerNG::Client.new(:env => @env, :project_id => @project_id)
17
30
 
18
31
  project = client.projects.get
19
-
20
- IronCore::Logger.info 'IronWorkerNG', "Working with project '#{project.name}' ('#{project.id}')"
32
+
33
+ log "Project '#{project.name}' with id='#{project.id}'"
21
34
 
22
35
  client
23
36
  end
24
37
 
25
- def env_opt(opts)
38
+ def common_opts(opts)
26
39
  opts.on('-e', '--env ENV', 'environment') do |v|
27
40
  @env = v
28
41
  end
42
+
43
+ opts.on('--project-id PROJECT_ID', 'project_id') do |v|
44
+ @project_id = v
45
+ end
46
+ end
47
+
48
+ def parse_time(str)
49
+ t = Time.parse(str)
50
+
51
+ return nil if t == Time.utc(1)
52
+
53
+ def t.to_s
54
+ strftime('%a %b %-d %T')
55
+ end
56
+
57
+ return t
29
58
  end
30
59
 
31
60
  if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
@@ -33,48 +62,42 @@ if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
33
62
  exit 0
34
63
  end
35
64
 
36
- if $*.size == 0 || (not ['codes.create', 'upload', 'tasks.create', 'queue', 'schedules.create', 'schedule', 'tasks.log', 'log', 'run'].include?($*[0]))
65
+ if $*.size == 0 || (not ['upload', 'queue', 'retry', 'schedule', 'log', 'run', 'webhook', 'info', 'install'].include?($*[0]))
37
66
  puts 'usage: iron_worker COMMAND [OPTIONS]'
38
- puts ' COMMAND: codes.create (upload), tasks.create (queue), schedules.create (schedule), tasks.log (log), run'
67
+ puts ' COMMAND: upload, queue, retry, schedule, log, run, webhook, info, install'
39
68
  puts ' run iron_worker COMMAND --help to get more information about each command'
40
69
  exit 1
41
70
  end
42
71
 
43
72
  command = $*.shift
44
73
 
45
- command = 'codes.create' if command == 'upload'
46
- command = 'tasks.create' if command == 'queue'
47
- command = 'schedules.create' if command == 'schedule'
48
- command = 'tasks.log' if command == 'log'
49
-
50
- IronCore::Logger.logger.formatter = IronWorkerCLILoggerFormatter.new
51
-
52
74
  if $*.include?('--debug')
53
75
  IronCore::Logger.logger.level = ::Logger::DEBUG
54
76
 
55
77
  $*.reject! { |p| p == '--debug' }
56
78
  end
57
79
 
58
- if command == 'codes.create'
59
- if $*.size > 0 && $*[0][0] != '-'
60
- $*.unshift('-n')
61
- end
80
+ if command == 'upload'
81
+ options = {}
62
82
 
63
83
  name = nil
64
- options = {}
65
84
 
66
85
  opts = OptionParser.new do |opts|
67
- opts.banner = "usage: iron_worker #{command} [OPTIONS]"
86
+ opts.banner = "usage: iron_worker upload CODE_PACKAGE_NAME_OR_PATH_TO_WORKERFILE [OPTIONS]"
68
87
 
69
- opts.on('-n', '--name NAME', 'code name or workerfile') do |v|
88
+ opts.on('-n', '--name NAME', 'override for code name') do |v|
70
89
  name = v
71
90
  end
72
91
 
73
- opts.on('-c', '--max-concurrency CONCURENCY', Integer, 'max number of concurrent workers for this code package') do |v|
92
+ opts.on('-c', '--max-concurrency CONCURRENCY', Integer, 'max number of concurrent workers for this code package') do |v|
74
93
  options[:max_concurrency] = v
75
94
  end
76
95
 
77
- env_opt(opts)
96
+ opts.on('-a', '--async', 'don\'t wait for package build') do |v|
97
+ options[:async] = true
98
+ end
99
+
100
+ common_opts(opts)
78
101
  end
79
102
 
80
103
  begin
@@ -84,26 +107,46 @@ if command == 'codes.create'
84
107
  exit 1
85
108
  end
86
109
 
87
- if name.nil?
110
+ unless $*.size == 1
111
+ puts 'Please specify name or path to workerfile'
88
112
  puts opts
89
113
  exit 1
90
114
  end
91
115
 
92
116
  client = create_client
93
117
 
94
- code = IronWorkerNG::Code::Base.new(name)
95
-
96
- IronCore::Logger.info 'IronWorkerNG', "Worker '#{code.name}' upload started"
97
-
98
- client.codes.create(code, options)
118
+ log "#{LOG_GROUP}Discovering workerfile"
99
119
 
100
- IronCore::Logger.info 'IronWorkerNG', "Worker '#{code.name}' uploaded"
101
- elsif command == 'tasks.create' || command == 'schedules.create'
102
- if $*.size > 0 && $*[0][0] != '-'
103
- $*.unshift('-n')
104
- end
120
+ code = IronWorkerNG::Code::Base.new($*[0])
105
121
 
106
- name = nil
122
+ code.name(name) if name
123
+
124
+ log "Code package name is '#{code.name}'"
125
+
126
+ log "Max concurrency set to '#{options[:max_concurrency]}'" if options[:max_concurrency]
127
+
128
+ if code.remote_build_command
129
+ log "#{LOG_GROUP}Remote building '#{code.name}'"
130
+
131
+ async = options[:async]
132
+
133
+ builder_task_id = client.codes.create(code, options)
134
+
135
+ if async
136
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{builder_task_id}' for more info"
137
+ else
138
+ # TODO: output the same info as for builderless upload
139
+ end
140
+ else
141
+ log "#{LOG_GROUP}Uploading code package"
142
+
143
+ code_id = client.codes.create(code, options).id
144
+ code_info = client.codes.get(code_id)
145
+
146
+ log "Code package uploaded with id='#{code_id}' and revision='#{code_info.rev}'"
147
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code_id}' for more info"
148
+ end
149
+ elsif command == 'queue' || command == 'schedule'
107
150
  payload = nil
108
151
  payload_file = nil
109
152
 
@@ -119,11 +162,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
119
162
  print_id = false
120
163
 
121
164
  opts = OptionParser.new do |opts|
122
- opts.banner = "usage: iron_worker #{command} [OPTIONS]"
123
-
124
- opts.on('-n', '--name NAME', 'code name') do |v|
125
- name = v
126
- end
165
+ opts.banner = "usage: iron_worker #{command} CODE_PACKAGE_NAME [OPTIONS]"
127
166
 
128
167
  opts.on('-p', '--payload PAYLOAD', String, 'payload to pass') do |v|
129
168
  payload = v
@@ -145,7 +184,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
145
184
  delay = v
146
185
  end
147
186
 
148
- if command == 'schedules.create'
187
+ if command == 'schedule'
149
188
  opts.on('--start-at TIME', 'start task at specified time') do |v|
150
189
  start_at = Time.parse(v)
151
190
  end
@@ -167,7 +206,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
167
206
  print_id = true
168
207
  end
169
208
 
170
- env_opt(opts)
209
+ common_opts(opts)
171
210
  end
172
211
 
173
212
  begin
@@ -177,11 +216,14 @@ elsif command == 'tasks.create' || command == 'schedules.create'
177
216
  exit 1
178
217
  end
179
218
 
180
- if name.nil?
219
+ unless $*.size == 1
220
+ puts 'Please specify code package name'
181
221
  puts opts
182
222
  exit 1
183
223
  end
184
224
 
225
+ name = $*[0]
226
+
185
227
  if payload.nil? and (not payload_file.nil?)
186
228
  payload = File.read(payload_file)
187
229
  end
@@ -192,7 +234,7 @@ elsif command == 'tasks.create' || command == 'schedules.create'
192
234
  options[:timeout] = timeout unless timeout.nil?
193
235
  options[:delay] = delay unless delay.nil?
194
236
 
195
- if command == 'schedules.create'
237
+ if command == 'schedule'
196
238
  options[:start_at] = start_at unless start_at.nil?
197
239
  options[:end_at] = end_at unless end_at.nil?
198
240
  options[:run_times] = run_times unless run_times.nil?
@@ -203,38 +245,74 @@ elsif command == 'tasks.create' || command == 'schedules.create'
203
245
 
204
246
  id = nil
205
247
 
206
- if command == 'tasks.create'
248
+ if command == 'queue'
249
+ log "#{LOG_GROUP}Queueing task"
250
+
207
251
  id = client.tasks.create(name, payload, options).id
208
252
 
209
- IronCore::Logger.info 'IronWorkerNG', "Worker '#{name}' queued"
253
+ log "#{LOG_GROUP}Worker '#{name}' queued with id='#{id}'"
254
+
255
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{id}' for more info"
210
256
  else
257
+ log "#{LOG_GROUP}Scheduling task"
258
+
211
259
  id = client.schedules.create(name, payload, options).id
212
260
 
213
- IronCore::Logger.info 'IronWorkerNG', "Worker '#{name}' scheduled"
261
+ log "#{LOG_GROUP}Worker '#{name}' scheduled with id='#{id}'"
262
+
263
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/scheduled_jobs/#{id}' for more info"
214
264
  end
215
265
 
216
266
  puts id if print_id
217
- elsif command == 'tasks.log'
218
- if $*.size > 0 && $*[0][0] != '-'
219
- $*.unshift('-t')
267
+ elsif command == 'retry'
268
+ options = {}
269
+
270
+ opts = OptionParser.new do |opts|
271
+ opts.banner = "usage: iron_worker retry TASK_ID [OPTIONS]"
272
+
273
+ opts.on('--delay DELAY', Integer, 'delay before start in seconds') do |v|
274
+ options[:delay] = v
275
+ end
276
+
277
+ common_opts(opts)
278
+ end
279
+
280
+ begin
281
+ opts.parse!
282
+ rescue OptionParser::ParseError
283
+ puts $!.to_s
284
+ exit 1
220
285
  end
221
286
 
222
- task_id = nil
287
+ unless $*.size == 1
288
+ puts 'Please specify task id'
289
+ puts opts
290
+ exit 1
291
+ end
292
+
293
+ task_id = $*.first
294
+
295
+ client = create_client
296
+
297
+ log "#{LOG_GROUP}Retrying task with id='#{task_id}'"
298
+
299
+ retry_task_id = client.tasks.retry(task_id, options).id
300
+
301
+ log "Retry task id='#{retry_task_id}'"
302
+
303
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{retry_task_id}' for more info"
304
+ elsif command == 'log'
223
305
  live = false
224
306
  wait = false
225
307
 
226
308
  opts = OptionParser.new do |opts|
227
- opts.banner = "usage: iron_worker #{command} [OPTIONS]"
228
-
229
- opts.on('-t', '--task-id ID', 'task id') do |v|
230
- task_id = v
231
- end
309
+ opts.banner = "usage: iron_worker log TASK_ID [OPTIONS]"
232
310
 
233
311
  opts.on('-w', '--wait', 'wait for task') do |v|
234
312
  wait = true
235
313
  end
236
314
 
237
- env_opt(opts)
315
+ common_opts(opts)
238
316
  end
239
317
 
240
318
  begin
@@ -244,13 +322,18 @@ elsif command == 'tasks.log'
244
322
  exit 1
245
323
  end
246
324
 
247
- if task_id.nil?
325
+ unless $*.size == 1
326
+ puts 'Please specify task id'
248
327
  puts opts
249
328
  exit 1
250
329
  end
251
330
 
331
+ task_id = $*.first
332
+
252
333
  client = create_client
253
334
 
335
+ log "#{LOG_GROUP}Getting log for task with id='#{task_id}'"
336
+
254
337
  log = ''
255
338
 
256
339
  if live
@@ -287,20 +370,11 @@ elsif command == 'tasks.log'
287
370
  end
288
371
  end
289
372
  elsif command == 'run'
290
- if $*.size > 0 && $*[0][0] != '-'
291
- $*.unshift('-n')
292
- end
293
-
294
- name = nil
295
373
  payload = nil
296
374
  payload_file = nil
297
375
 
298
376
  opts = OptionParser.new do |opts|
299
- opts.banner = "usage: iron_worker #{command} [OPTIONS]"
300
-
301
- opts.on('-n', '--name NAME', 'code name or workerfile') do |v|
302
- name = v
303
- end
377
+ opts.banner = "usage: iron_worker run CODE_PACKAGE_NAME_OR_PATH_TO_WORKERFILE [OPTIONS]"
304
378
 
305
379
  opts.on('-p', '--payload PAYLOAD', String, 'payload to pass') do |v|
306
380
  payload = v
@@ -309,6 +383,8 @@ elsif command == 'run'
309
383
  opts.on('-f', '--payload-file PAYLOAD_FILE', String, 'payload file to pass') do |v|
310
384
  payload_file = v
311
385
  end
386
+
387
+ common_opts(opts)
312
388
  end
313
389
 
314
390
  begin
@@ -318,7 +394,8 @@ elsif command == 'run'
318
394
  exit 1
319
395
  end
320
396
 
321
- if name.nil?
397
+ unless $*.size == 1
398
+ puts 'Please specify code package name or workerfile'
322
399
  puts opts
323
400
  exit 1
324
401
  end
@@ -327,9 +404,168 @@ elsif command == 'run'
327
404
  payload = File.read(payload_file)
328
405
  end
329
406
 
330
- code = IronWorkerNG::Code::Base.new(name)
407
+ log "#{LOG_GROUP}Discovering workerfile"
408
+
409
+ code = IronWorkerNG::Code::Base.new($*.first)
410
+
411
+ log "Code package name is '#{code.name}'"
412
+
413
+ log "#{LOG_GROUP}Running '#{code.name}'"
331
414
 
332
- IronCore::Logger.info 'IronWorkerNG', "Worker '#{name}' run started"
333
-
334
415
  code.run(payload)
416
+ elsif command == 'webhook'
417
+ opts = OptionParser.new do |opts|
418
+ opts.banner = 'usage: iron_worker webhook CODE_PACKAGE_NAME [OPTIONS]'
419
+
420
+ common_opts(opts)
421
+ end
422
+
423
+ begin
424
+ opts.parse!
425
+ rescue OptionParser::ParseError
426
+ puts $!.to_s
427
+ exit 1
428
+ end
429
+
430
+ unless $*.size == 1
431
+ puts 'Please specify code package name'
432
+ puts opts
433
+ exit 1
434
+ end
435
+
436
+ name = $*[0]
437
+
438
+ client = create_client
439
+
440
+ log "#{LOG_GROUP}Detecting webhook for code package with name='#{name}'"
441
+ log "Use POST to 'https://worker-aws-us-east-1.iron.io/2/projects/#{client.api.project_id}/tasks/webhook?code_name=#{name}&oauth=#{client.api.token}' to invoke worker via webhook"
442
+ elsif command == 'info'
443
+ unless $*.size == 2 or %w(info task ).include? $*.first
444
+ puts 'Usage: iron_worker info <code|task|schedule> NAME_OR_ID'
445
+ exit 1
446
+ end
447
+
448
+ entity, id = $*
449
+ client = create_client
450
+
451
+ if entity == 'code'
452
+ code = client.codes.list(:all => true).find { |c| c.name == id }
453
+
454
+ unless code
455
+ log "#{LOG_GROUP}Code named '#{id}' not found"
456
+ exit 1
457
+ end
458
+
459
+ latest_change = parse_time(code.latest_change)
460
+ created_at = parse_time(code.created_at)
461
+ (<<EOL
462
+ #{LOG_GROUP}Code package '#{code.name}'
463
+ ID: #{code.id}
464
+ Created: #{created_at}
465
+ Last Modified: #{latest_change}
466
+ Revision: #{code.rev}
467
+ All Revisions: https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code.id}
468
+ Tasks: https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{code.id}/activity
469
+ EOL
470
+ ).lines.each{ |msg| log msg.chomp }
471
+ end
472
+
473
+ if entity == 'task'
474
+ begin
475
+ prev_level = IronCore::Logger.logger.level
476
+ IronCore::Logger.logger.level = ::Logger::FATAL
477
+ task = client.tasks.get(id)
478
+ rescue IronCore::Error, Rest::RestError
479
+ # iron_core throws exception if id not found
480
+ IronCore::Logger.logger.level = prev_level
481
+ log "#{LOG_GROUP}Task with id #{id} not found"
482
+ exit(1)
483
+ ensure
484
+ IronCore::Logger.logger.level = prev_level
485
+ end
486
+
487
+ queued = parse_time(task.created_at)
488
+ started = parse_time(task.start_time)
489
+ finished = parse_time(task.end_time)
490
+
491
+ if finished
492
+ total = finished - started
493
+
494
+ seconds = total % 60
495
+ minutes = (total / 60) % 60
496
+ hours = total / (60 * 60)
497
+
498
+ duration = format("%02d:%02d:%02d", hours, minutes, seconds)
499
+ end
500
+
501
+ log "#{LOG_GROUP}Task id #{id} found"
502
+ log "Code Package: '#{task.code_name}', rev #{task.code_rev}, download: https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{task.code_id}/download?hid=#{task.code_history_id}"
503
+ log " Status: #{task.status}"
504
+ log " Priority: #{task.priority}" if task.priority
505
+ log " Queued: #{queued}"
506
+ log " Started: #{started}" if started
507
+ log " Finished: #{finished}" if finished
508
+ log " Duration: #{duration}" if finished
509
+ log " Payload: #{task.payload}" unless task.payload == 'null'
510
+ log "Task Details: https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{task.id}"
511
+ end
512
+
513
+ if entity == 'schedule'
514
+ begin
515
+ prev_level = IronCore::Logger.logger.level
516
+ IronCore::Logger.logger.level = ::Logger::FATAL
517
+ schedule = client.schedules.get(id)
518
+ rescue IronCore::Error, Rest::RestError
519
+ # iron_core throws exception if id not found
520
+ IronCore::Logger.logger.level = prev_level
521
+ log "#{LOG_GROUP}Schedule with id #{id} not found"
522
+ exit(1)
523
+ ensure
524
+ IronCore::Logger.logger.level = prev_level
525
+ end
526
+
527
+ start_at = parse_time(schedule.start_at)
528
+ end_at = parse_time(schedule.end_at)
529
+ next_start = parse_time(schedule.next_start)
530
+ last_run_time = parse_time(schedule.last_run_time)
531
+
532
+ log "#{LOG_GROUP}Schedule id #{id} found"
533
+ log " Code Name: #{schedule.code_name}"
534
+ log " Created: #{parse_time(schedule.created_at)}"
535
+ log " Message: #{schedule.msg}" if schedule.msg
536
+ log " Status: #{schedule.status}"
537
+ log " Start: #{start_at}" if start_at
538
+ log " End: #{end_at}" if end_at
539
+ log "Next Start: #{next_start}" if next_start
540
+ log " Run Count: #{schedule.run_count}" if schedule.run_count
541
+ log " Payload: #{schedule.payload}" unless schedule.payload == 'null'
542
+ log " Details: https://hud.iron.io/tq/projects/#{client.api.project_id}/scheduled_jobs/#{id}"
543
+ end
544
+ elsif command == 'install'
545
+ opts = OptionParser.new do |opts|
546
+ opts.banner = 'usage: iron_worker install CODE_PACKAGE_NAME_OR_PATH_TO_WORKERFILE [OPTIONS]'
547
+
548
+ common_opts(opts)
549
+ end
550
+
551
+ begin
552
+ opts.parse!
553
+ rescue OptionParser::ParseError
554
+ puts $!.to_s
555
+ exit 1
556
+ end
557
+
558
+ unless $*.size == 1
559
+ puts 'Please specify code package name or path to workerfile'
560
+ puts opts
561
+ exit 1
562
+ end
563
+
564
+ name = $*[0]
565
+
566
+ log "#{LOG_GROUP}Installing worker dependencies for code package with name='#{name}'"
567
+
568
+ code = IronWorkerNG::Code::Base.new(name)
569
+
570
+ code.install
335
571
  end
@@ -91,6 +91,11 @@ module IronWorkerNG
91
91
  parse_response(post("projects/#{@project_id}/tasks/#{id}/progress", options))
92
92
  end
93
93
 
94
+ def tasks_retry(id, options = {})
95
+ check_id(id)
96
+ parse_response(post("projects/#{@project_id}/tasks/#{id}/retry", options))
97
+ end
98
+
94
99
  def schedules_list(options = {})
95
100
  parse_response(get("projects/#{@project_id}/schedules", options))
96
101
  end
@@ -51,7 +51,27 @@ module IronWorkerNG
51
51
  def codes_list(options = {})
52
52
  IronCore::Logger.debug 'IronWorkerNG', "Calling codes.list with options='#{options.to_s}'"
53
53
 
54
- @api.codes_list(options)['codes'].map { |c| OpenStruct.new(c) }
54
+ all = options.delete(:all) || options.delete('all')
55
+
56
+ if all
57
+ result = []
58
+
59
+ page = options[:page] || options['page'] || 0
60
+ per_page = options[:per_page] || options['per_page'] || 100
61
+
62
+ while true
63
+ next_codes = codes_list(options.merge({:page => page}))
64
+
65
+ result += next_codes
66
+
67
+ break if next_codes.length != per_page
68
+ page += 1
69
+ end
70
+
71
+ result
72
+ else
73
+ @api.codes_list(options)['codes'].map { |c| OpenStruct.new(c) }
74
+ end
55
75
  end
56
76
 
57
77
  def codes_get(code_id)
@@ -63,6 +83,8 @@ module IronWorkerNG
63
83
  def codes_create(code, options = {})
64
84
  IronCore::Logger.debug 'IronWorkerNG', "Calling codes.create with code='#{code.to_s}' and options='#{options.to_s}'"
65
85
 
86
+ async = options.delete(:async) || options.delete('async')
87
+
66
88
  container_file = code.create_container
67
89
 
68
90
  if code.remote_build_command.nil?
@@ -70,13 +92,27 @@ module IronWorkerNG
70
92
  else
71
93
  builder_code_name = code.name + (code.name.capitalize == code.name ? '::Builder' : '::builder')
72
94
 
95
+ IronCore::Logger.info 'IronWorkerNG', 'Uploading builder'
96
+
73
97
  @api.codes_create(builder_code_name, container_file, 'sh', '__runner__.sh', options)
74
98
 
75
99
  builder_task = tasks.create(builder_code_name, :code_name => code.name, :client_options => @api.options.to_json, :codes_create_options => options.to_json)
100
+
101
+ if async
102
+ IronCore::Logger.info 'IronWorkerNG', 'Running builder asynchronously'
103
+
104
+ File.unlink(container_file)
105
+
106
+ return builder_task.id
107
+ end
108
+
109
+ IronCore::Logger.info 'IronWorkerNG', 'Waiting for builder to complete'
110
+
76
111
  builder_task = tasks.wait_for(builder_task.id)
77
112
 
78
113
  unless builder_task.status == 'complete'
79
114
  log = tasks.log(builder_task.id)
115
+
80
116
  IronCore::Logger.error 'IronWorkerNG', 'Error while remote building worker: ' + log, IronCore::Error
81
117
  end
82
118
 
@@ -182,6 +218,14 @@ module IronWorkerNG
182
218
  task
183
219
  end
184
220
 
221
+ def tasks_retry(task_id, options = {})
222
+ IronCore::Logger.debug 'IronWorkerNG', "Calling tasks.retry with task_id='#{task_id}' and options='#{options.to_s}'"
223
+
224
+ res = @api.tasks_retry(task_id, options)
225
+
226
+ OpenStruct.new(res['tasks'][0])
227
+ end
228
+
185
229
  def schedules_list(options = {})
186
230
  IronCore::Logger.debug 'IronWorkerNG', "Calling schedules.list with options='#{options.to_s}'"
187
231
 
@@ -73,7 +73,7 @@ module IronWorkerNG
73
73
  src, clean = IronWorkerNG::Fetcher.fetch(wfile)
74
74
 
75
75
  unless src.nil?
76
- IronCore::Logger.info 'IronWorkerNG', "Using workerfile '#{wfile}'"
76
+ IronCore::Logger.info 'IronWorkerNG', "Found workerfile with path='#{wfile}'"
77
77
 
78
78
  eval(src)
79
79
 
@@ -136,7 +136,7 @@ module IronWorkerNG
136
136
  return @runtime unless runtime
137
137
 
138
138
  unless @runtime.nil?
139
- IronCore::Logger.error 'IronWorkerNG', "Runtime is already set to #{@runtime}", IronCore::Error
139
+ IronCore::Logger.error 'IronWorkerNG', "Runtime is already set to '#{@runtime}'", IronCore::Error
140
140
  end
141
141
 
142
142
  runtime_module = nil
@@ -281,6 +281,9 @@ RUNNER
281
281
  FileUtils.rm_f(container_name)
282
282
  end
283
283
 
284
+ def install
285
+ end
286
+
284
287
  def to_s
285
288
  "runtime='#{@runtime}', name='#{@name}', exec='#{@inside_builder || @exec.nil? ? '' : @exec.path}'"
286
289
  end
@@ -1,3 +1,6 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+
1
4
  require_relative '../../feature/ruby/merge_gem'
2
5
  require_relative '../../feature/ruby/merge_gemfile'
3
6
  require_relative '../../feature/ruby/merge_exec'
@@ -90,6 +93,26 @@ RUBY_RUNNER
90
93
  #{local ? 'GEM_PATH="" ' : ''}ruby __runner__.rb "$@"
91
94
  RUN_CODE
92
95
  end
96
+
97
+ def install
98
+ gemfile_dir = Dir.tmpdir + '/' + Dir::Tmpname.make_tmpname('iron-worker-ng-', 'gemfile')
99
+
100
+ FileUtils.mkdir(gemfile_dir)
101
+
102
+ gemfile = File.open(gemfile_dir + '/Gemfile', 'w')
103
+
104
+ gemfile.puts('source :rubygems')
105
+
106
+ @merge_gem_reqs.each do |req|
107
+ gemfile.puts("gem '#{req.name}', '#{req.requirement.to_s}'")
108
+ end
109
+
110
+ gemfile.close
111
+
112
+ puts `cd #{gemfile_dir} && bundle install`
113
+
114
+ FileUtils.rm_r(gemfile_dir)
115
+ end
93
116
  end
94
117
  end
95
118
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Binary::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging binary exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected binary exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Go::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging go exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected go exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -41,7 +41,7 @@ module IronWorkerNG
41
41
 
42
42
  @exec = IronWorkerNG::Feature::Java::MergeExec::Feature.new(self, path, klass)
43
43
 
44
- IronCore::Logger.info 'IronWorkerNG', "Merging java exec with path='#{path}' and class='#{klass}'"
44
+ IronCore::Logger.info 'IronWorkerNG', "Detected java exec with path='#{path}'#{klass.nil? ? '' : " and class='#{klass}'"}"
45
45
 
46
46
  @features << @exec
47
47
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Mono::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging mono exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected mono exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Node::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging node exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected node exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Perl::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging perl exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected perl exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::PHP::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging php exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected php exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -35,7 +35,7 @@ module IronWorkerNG
35
35
 
36
36
  @exec = IronWorkerNG::Feature::Python::MergeExec::Feature.new(self, path)
37
37
 
38
- IronCore::Logger.info 'IronWorkerNG', "Merging python exec with path='#{path}'"
38
+ IronCore::Logger.info 'IronWorkerNG', "Detected python exec with path='#{path}'"
39
39
 
40
40
  @features << @exec
41
41
  end
@@ -37,7 +37,7 @@ module IronWorkerNG
37
37
 
38
38
  @exec = IronWorkerNG::Feature::Ruby::MergeExec::Feature.new(self, path, klass)
39
39
 
40
- IronCore::Logger.info 'IronWorkerNG', "Merging ruby exec with path='#{path}' and class='#{klass}'"
40
+ IronCore::Logger.info 'IronWorkerNG', "Detected ruby exec with path='#{path}'#{klass.nil? ? '' : " and class='#{klass}'"}"
41
41
 
42
42
  @features << @exec
43
43
  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.9.6
4
+ version: 0.10.0
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-07-22 00:00:00.000000000 Z
13
+ date: 2012-08-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: iron_core
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: 997707347
165
+ hash: -556831631
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements: