iron_worker_ng 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec003beb156fbb334b0a0d1447742f434457e000
4
- data.tar.gz: dd390f78a508f82c0a6b5c909ea2015063ff1af0
3
+ metadata.gz: 98b0e00e293fcd4830606d9df08dcade43b6aa11
4
+ data.tar.gz: c815b1f91b12f0a065e8e258a995891f2f414627
5
5
  SHA512:
6
- metadata.gz: 5e89a774dc83290bc649b438b33d208bf5073d94fe8cab027a43bfff3858b10a3a23e0dcf584939e3d06625f7da59f60f4be9e4fcce0f1e7d4981597a6a808e9
7
- data.tar.gz: fbbfde46222f1178b00cc6338592bb7dd4c07f6c87c8f630e11082c72180f2d492d007db24207f6f0c1728bc2e26fcbf2a179abd5015765c09caac0ddb09d94b
6
+ metadata.gz: 242738189db79e8bc2219df6cec277751e985bc7ce6bafabf234feb48cf215ec9d83b343af17694a53f75d54c2add90fca1b3a97c434b995a6f4c8d157fc5218
7
+ data.tar.gz: 51d840ba457f9dfb0f7b8dec34b9c092cb9b5b288fff1ebf82a0115d61e128967750205eae555215b5acfd3f52577b86be7828d0df190aaef6ddc8ac5d1c8d94
data/README.md CHANGED
@@ -110,6 +110,7 @@ You can specify not only priority:
110
110
  - **timeout**: The maximum runtime of your task in seconds. No task can exceed 3600 seconds (60 minutes). The default is 3600 but can be set to a shorter duration.
111
111
  - **delay**: The number of seconds to delay before actually queuing the task. Default is 0.
112
112
  - **label**: Optional text label for your task.
113
+ - **cluster**: cluster name ex: "high-mem" or "dedicated". If not set default is set to "default" which is the public IronWorker cluster.
113
114
 
114
115
  ## Get task status
115
116
 
@@ -132,6 +133,21 @@ You can retry task by id using same payload and options:
132
133
  or
133
134
  ```ruby
134
135
  client.tasks.retry('5032f7360a4681382838e082', :delay => 10)
136
+
137
+ ## Pause or Resume task processing
138
+
139
+ You can temporarily pause or resume queued and scheduled tasks processing by code name:
140
+
141
+ iron_worker pause hello
142
+
143
+ iron_worker resume hello
144
+
145
+ or by code:
146
+ Pause or resume for the code package specified by `code_id`.
147
+
148
+ ```ruby
149
+ response = client.codes.pause_task_queue('1234567890')
150
+ response = client.codes.resume_task_queue('1234567890')
135
151
  ```
136
152
 
137
153
 
data/bin/iron_worker CHANGED
@@ -41,7 +41,7 @@ if $*.size == 1 && ($*[0] == '-v' || $*[0] == '--version')
41
41
  exit 0
42
42
  end
43
43
 
44
- commands = ['upload', 'patch', 'queue', 'retry', 'schedule', 'update', 'log', 'run', 'install', 'webhook', 'info', 'stacks']
44
+ commands = ['upload', 'patch', 'queue', 'retry', 'schedule', 'update', 'log', 'run', 'install', 'webhook', 'info', 'stacks', 'pause', 'resume']
45
45
 
46
46
  if $*.size == 0 || (not commands.include?($*[0]))
47
47
  puts 'usage: iron_worker COMMAND [OPTIONS]'
@@ -511,4 +511,33 @@ elsif command == 'update'
511
511
 
512
512
  @cli.update_schedule($*[0], params)
513
513
  end
514
+
515
+ elsif command == 'pause' || command == 'resume'
516
+ params = {}
517
+ options = {}
518
+
519
+ opts = OptionParser.new do |opts|
520
+ opts.banner = "usage: iron_worker #{command} CODE_PACKAGE_NAME"
521
+
522
+ common_opts(opts)
523
+ end
524
+
525
+ begin
526
+ opts.parse!
527
+ rescue OptionParser::ParseError
528
+ puts $!.to_s
529
+ exit 1
530
+ end
531
+
532
+ unless $*.size == 1
533
+ puts 'Please specify code package name'
534
+ puts opts
535
+ exit 1
536
+ end
537
+
538
+ if command == 'resume'
539
+ @cli.resume($*[0], params, options)
540
+ else
541
+ @cli.pause($*[0], params, options)
542
+ end
514
543
  end
@@ -62,6 +62,16 @@ module IronWorkerNG
62
62
  parse_response(get("projects/#{@project_id}/codes/#{id}/download", options), false)
63
63
  end
64
64
 
65
+ def codes_pause_task_queue(id, options = {})
66
+ check_id(id)
67
+ parse_response(post("projects/#{@project_id}/codes/#{id}/pause_task_queue", options))
68
+ end
69
+
70
+ def codes_resume_task_queue(id, options = {})
71
+ check_id(id)
72
+ parse_response(post("projects/#{@project_id}/codes/#{id}/resume_task_queue", options))
73
+ end
74
+
65
75
  def tasks_list(options = {})
66
76
  parse_response(get("projects/#{@project_id}/tasks", options))
67
77
  end
@@ -326,6 +326,52 @@ module IronWorkerNG
326
326
  display_table(data)
327
327
  end
328
328
 
329
+ def pause(name, params, options)
330
+ code = get_code_by_name(name)
331
+ log "Pausing task queue for code '#{code._id}'"
332
+
333
+ response = client.codes.pause_task_queue(code._id, options)
334
+
335
+ if response.msg == 'Paused'
336
+ log "Task queue and schedules for #{name} paused successfully"
337
+ elsif response.msg == 'Already paused'
338
+ log "Task queue and schedules for #{name} are already paused"
339
+ else
340
+ log 'Something went wrong'
341
+ end
342
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code._id}' for more info"
343
+ end
344
+
345
+ def resume(name, params, options)
346
+ code = get_code_by_name(name)
347
+ log "Resuming task queue for code '#{code._id}'"
348
+
349
+ response = client.codes.resume_task_queue(code._id, options)
350
+
351
+ if response.msg == 'Resumed'
352
+ log "Task queue and schedules for #{name} resumed successfully"
353
+ elsif response.msg == 'Already resumed'
354
+ log "Task queue and schedules for #{name} are already resumed"
355
+ else
356
+ log 'Something went wrong'
357
+ end
358
+ log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code._id}' for more info"
359
+ end
360
+
361
+ def get_code_by_name(name)
362
+ client
363
+
364
+ codes = client.codes.list({:all => true})
365
+ code = codes.find { |code| code.name == name }
366
+
367
+ unless code
368
+ log "Code package with name='#{name}' not found"
369
+ exit 1
370
+ end
371
+ code
372
+ end
373
+
374
+
329
375
  def parse_time(s)
330
376
  t = Time.parse(s)
331
377
 
@@ -276,6 +276,20 @@ EXEC_FILE
276
276
  @api.codes_download(code_id, options)
277
277
  end
278
278
 
279
+ def codes_pause_task_queue(code_id, options = {})
280
+ IronCore::Logger.debug 'IronWorkerNG', "Calling codes.pause_task_queue with code_id='#{code_id}' and options='#{options.to_s}'"
281
+
282
+ res = @api.codes_pause_task_queue(code_id, options)
283
+ OpenStruct.new(res)
284
+ end
285
+
286
+ def codes_resume_task_queue(code_id, options = {})
287
+ IronCore::Logger.debug 'IronWorkerNG', "Calling codes.resume_task_queue with code_id='#{code_id}' and options='#{options.to_s}'"
288
+
289
+ res = @api.codes_resume_task_queue(code_id, options)
290
+ OpenStruct.new(res)
291
+ end
292
+
279
293
  def tasks_list(options = {})
280
294
  IronCore::Logger.debug 'IronWorkerNG', "Calling tasks.list with options='#{options.to_s}'"
281
295
 
@@ -10,7 +10,7 @@ module IronWorkerNG
10
10
  <?php
11
11
  /* #{IronWorkerNG.full_version} */
12
12
 
13
- function getArgs() {
13
+ function getArgs($assoc = true) {
14
14
  global $argv;
15
15
 
16
16
  $args = array('task_id' => null, 'dir' => null, 'payload' => array(), 'config' => null);
@@ -24,7 +24,7 @@ function getArgs() {
24
24
  if ($v == '-payload' && file_exists($argv[$k + 1])) {
25
25
  $args['payload'] = file_get_contents($argv[$k + 1]);
26
26
 
27
- $parsed_payload = json_decode($args['payload']);
27
+ $parsed_payload = json_decode($args['payload'], $assoc);
28
28
 
29
29
  if ($parsed_payload != null) {
30
30
  $args['payload'] = $parsed_payload;
@@ -34,7 +34,7 @@ function getArgs() {
34
34
  if ($v == '-config' && file_exists($argv[$k + 1])) {
35
35
  $args['config'] = file_get_contents($argv[$k + 1]);
36
36
 
37
- $parsed_config = json_decode($args['config'], true);
37
+ $parsed_config = json_decode($args['config'], $assoc);
38
38
 
39
39
  if ($parsed_config != null) {
40
40
  $args['config'] = $parsed_config;
@@ -45,14 +45,14 @@ function getArgs() {
45
45
  return $args;
46
46
  }
47
47
 
48
- function getPayload() {
49
- $args = getArgs();
48
+ function getPayload($assoc = true) {
49
+ $args = getArgs($assoc);
50
50
 
51
51
  return $args['payload'];
52
52
  }
53
53
 
54
- function getConfig(){
55
- $args = getArgs();
54
+ function getConfig($assoc = true){
55
+ $args = getArgs($assoc);
56
56
 
57
57
  return $args['config'];
58
58
  }
@@ -1,5 +1,5 @@
1
1
  module IronWorkerNG
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
 
4
4
  def self.version
5
5
  VERSION
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: 1.6.1
4
+ version: 1.6.2
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: 2014-12-09 00:00:00.000000000 Z
12
+ date: 2014-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core