iron_worker 2.4.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +352 -0
  4. data/iron_worker.gemspec +3 -8
  5. data/lib/iron_worker.rb +13 -51
  6. data/lib/iron_worker/api_client.rb +152 -0
  7. data/lib/iron_worker/version.rb +9 -1
  8. data/lib/iron_worker/worker_helper.rb +72 -0
  9. metadata +18 -183
  10. data/README.markdown +0 -73
  11. data/lib/generators/iron_worker/iron_worker_generator.rb +0 -13
  12. data/lib/generators/iron_worker/templates/template_worker.erb +0 -7
  13. data/lib/iron_worker/api.rb +0 -244
  14. data/lib/iron_worker/base.rb +0 -449
  15. data/lib/iron_worker/config.rb +0 -287
  16. data/lib/iron_worker/rails2_init.rb +0 -8
  17. data/lib/iron_worker/railtie.rb +0 -16
  18. data/lib/iron_worker/server/overrides.rb +0 -198
  19. data/lib/iron_worker/server/runner.rb +0 -82
  20. data/lib/iron_worker/service.rb +0 -644
  21. data/lib/iron_worker/used_in_worker.rb +0 -11
  22. data/lib/iron_worker/utils.rb +0 -11
  23. data/rails/init.rb +0 -0
  24. data/test/Gemfile +0 -36
  25. data/test/Gemfile.lock +0 -169
  26. data/test/README.md +0 -5
  27. data/test/batch_run.rb +0 -121
  28. data/test/config_sample.yml +0 -13
  29. data/test/models/cool_model.rb +0 -7
  30. data/test/models/db_model.rb +0 -6
  31. data/test/models/model_1.rb +0 -16
  32. data/test/models/model_2.rb +0 -16
  33. data/test/quick_run.rb +0 -36
  34. data/test/quick_schedule.rb +0 -18
  35. data/test/resources/something.yml +0 -4
  36. data/test/simple_script.rb +0 -11
  37. data/test/test_base.rb +0 -79
  38. data/test/test_database.rb +0 -31
  39. data/test/test_gems.rb +0 -31
  40. data/test/test_inheritance.rb +0 -25
  41. data/test/test_iron_worker.rb +0 -194
  42. data/test/test_merging.rb +0 -51
  43. data/test/test_non_worker_script.rb +0 -14
  44. data/test/test_rails.rb +0 -35
  45. data/test/test_scheduling.rb +0 -74
  46. data/test/test_scheduling_no_active_support.rb +0 -37
  47. data/test/test_service.rb +0 -28
  48. data/test/test_uploads.rb +0 -30
  49. data/test/test_webhooks.rb +0 -45
  50. data/test/v2quick.rb +0 -29
  51. data/test/workers/awesome_job.rb +0 -26
  52. data/test/workers/aws_s3_worker.rb +0 -10
  53. data/test/workers/big_data_worker.rb +0 -15
  54. data/test/workers/big_gems_worker.rb +0 -35
  55. data/test/workers/cool_worker.rb +0 -14
  56. data/test/workers/db_worker.rb +0 -27
  57. data/test/workers/fail_worker.rb +0 -10
  58. data/test/workers/gem_dependency_worker.rb +0 -20
  59. data/test/workers/hacker_worker.rb +0 -65
  60. data/test/workers/iw_test_worker.rb +0 -22
  61. data/test/workers/iw_test_worker_2.rb +0 -53
  62. data/test/workers/iw_test_worker_3.rb +0 -17
  63. data/test/workers/local_vs_remote_worker.rb +0 -9
  64. data/test/workers/merging_worker.rb +0 -40
  65. data/test/workers/mq_worker.rb +0 -21
  66. data/test/workers/one_line_worker.rb +0 -10
  67. data/test/workers/prawn_worker.rb +0 -32
  68. data/test/workers/progress_worker.rb +0 -26
  69. data/test/workers/qb_worker.rb +0 -17
  70. data/test/workers/rails_worker.rb +0 -24
  71. data/test/workers/rails_worker2.rb +0 -12
  72. data/test/workers/requiring_worker.rb +0 -4
  73. data/test/workers/running_back_worker.rb +0 -7
  74. data/test/workers/scheduled_worker.rb +0 -15
  75. data/test/workers/second_worker.rb +0 -16
  76. data/test/workers/third_worker.rb +0 -6
  77. data/test/workers/webhook_worker.rb +0 -7
  78. data/test/zip_vs_gzip.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45f10beed01a145026c8ecf904b458d2d98c0de3
4
- data.tar.gz: f915424385129c96823f092213ac9985ffd37c43
3
+ metadata.gz: 1a86914c6a2dabca1b3177b74f0ab13c397a3b2c
4
+ data.tar.gz: 3acacecad9b0e88ffd4ab60eddf6a8b2f1d7f182
5
5
  SHA512:
6
- metadata.gz: aec12031b24ba4b60d3a55358f671827186c2464231d5ba3e8c4c62f68f6ad4ed998e4c9483d4d2ea6c33d393d0ead3c2a8ae6839dc1ae0c0e30e2245a88d5af
7
- data.tar.gz: 248199b7bd787670c6f3035af208f850a25c427bd3d7f4efc2caf1893c4dfb989b011824dd97408475a4df7bb1233d3d267b6ca4514d4079ba672f4989c1442c
6
+ metadata.gz: c2cdf0dd340e8c7e2a6ecc479cf2cc43873e7b00e3a96d6e58e8fd7f14331c421805e2f99fb3a5eb6044cf9fc22c99b5f97e3dc0763d3658902b5097cee50ede
7
+ data.tar.gz: 421c43bc0a41cfd24ffb492089c7ad3312b0f470ba56cd3e8607f5988cf1a998349c5e0a967c196c9b41d72cd913798f0970c437f9b78e35709d711e34c9c347
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  pkg
3
3
  test/config.yml
4
4
  *.sublime-*
5
+ *.gem
data/README.md ADDED
@@ -0,0 +1,352 @@
1
+ # Introduction
2
+
3
+ To run your code in cloud you need to do three things:
4
+
5
+ - **Create code package**
6
+ - **Upload code package**
7
+ - **Queue or schedule tasks** for execution
8
+
9
+ TODO: Link to dockerworker.
10
+
11
+ While you can use [REST APIs](http://dev.iron.io/worker/reference/api) for that, it's easier to use an
12
+ IronWorker library created specifically for your language of choice, such as this gem, IronWorker.
13
+
14
+ # Preparing Your Environment
15
+
16
+ You'll need to register at http://iron.io/ and get your credentials to use IronWorker. Each account can have an unlimited number of projects, so take advantage of it by creating separate projects for development, testing and production. Each project is identified by a unique project ID and requires your access token before it will perform any action, like uploading or queuing workers.
17
+
18
+ Also, you'll need a Ruby 1.9 interpreter and the IronWorker gem. Install it using following command.
19
+
20
+ ```sh
21
+ gem install iron_worker
22
+ ```
23
+
24
+
25
+ ## Queue Up a Task for your Worker
26
+
27
+ TODO: Drop this, should use new cli tool for queueing.
28
+
29
+ You can quicky queue up a task for your worker from the command line using:
30
+
31
+ iron_worker queue hello
32
+
33
+ Use the `-p` parameter to pass in a payload:
34
+
35
+ iron_worker queue hello -p "{\"hi\": \"world\"}"
36
+
37
+ Use the `--wait` parameter to queue a task, wait for it to complete and print the log.
38
+
39
+ iron_worker queue hello -p "{\"hi\": \"world\"}" --wait
40
+
41
+ ### Queue up a task from code
42
+
43
+ Most commonly you'll be queuing up tasks from code though, so you can do this:
44
+
45
+ ```ruby
46
+ require "iron_worker_ng"
47
+ client = IronWorker::Client.new
48
+ 100.times do
49
+ client.tasks.create("hello", "foo"=>"bar")
50
+ end
51
+ ```
52
+
53
+ ### Setting Task Priority
54
+
55
+ TODO: Drop this, use new cli tool
56
+
57
+ You can specify priority of the task using `--priority` parameter:
58
+
59
+ ```ruby
60
+ iron_worker queue hello --priority 0 # default value, lowest priority
61
+ iron_worker queue hello --priority 1 --label 'medium priority task' # medium priority
62
+ ```
63
+
64
+ Value of priority parameter means the priority queue to run the task in. Valid values are 0, 1, and 2. 0 is the default.
65
+
66
+ From code you can set the priority like it done in snippet below:
67
+
68
+ ```ruby
69
+ client.tasks.create("hello", some_params, priority: 2) # highest priority
70
+ ```
71
+
72
+ ### Setting additional Options
73
+
74
+
75
+ You can specify not only priority:
76
+
77
+ - **priority**: Setting the priority of your job. Valid values are 0, 1, and 2. The default is 0.
78
+ - **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.
79
+ - **delay**: The number of seconds to delay before actually queuing the task. Default is 0.
80
+ - **label**: Optional text label for your task.
81
+ - **cluster**: cluster name ex: "high-mem" or "dedicated". If not set default is set to "default" which is the public IronWorker cluster.
82
+
83
+ ## Get task status
84
+
85
+
86
+ TODO: Drop, use new cli
87
+
88
+ When you call `iron_worker queue X`, you'll see the task ID in the output which you can use to get the status.
89
+
90
+ iron_worker info task 5032f7360a4681382838e082
91
+
92
+ ## Get task log
93
+
94
+
95
+ TODO: Drop, use new cli
96
+
97
+ Similar to getting status, get the task ID in the queue command output, then:
98
+
99
+ iron_worker log 5032f7360a4681382838e082 --wait
100
+
101
+ ## Retry a Task
102
+
103
+
104
+ TODO: Drop, use new cli
105
+
106
+ You can retry task by id using same payload and options:
107
+
108
+ iron_worker retry 5032f7360a4681382838e082
109
+
110
+ or
111
+ ```ruby
112
+ client.tasks.retry('5032f7360a4681382838e082', :delay => 10)
113
+
114
+ ## Pause or Resume task processing
115
+
116
+
117
+ TODO: Drop, use new cli
118
+
119
+ You can temporarily pause or resume queued and scheduled tasks processing by code name:
120
+
121
+ iron_worker pause hello
122
+
123
+ iron_worker resume hello
124
+
125
+ or by code:
126
+ Pause or resume for the code package specified by `code_id`.
127
+
128
+ ```ruby
129
+ response = client.codes.pause_task_queue('1234567890')
130
+ response = client.codes.resume_task_queue('1234567890')
131
+ ```
132
+
133
+
134
+ ### Debugging
135
+
136
+ To get a bunch of extra output to debug things, turn it on using:
137
+
138
+ IronCore::Logger.logger.level = ::Logger::DEBUG
139
+
140
+
141
+ # Queue Up Tasks for Your Worker
142
+
143
+ Now that the code is uploaded, we can create/queue up tasks. You can call this over and over
144
+ for as many tasks as you want.
145
+
146
+ ```ruby
147
+ client.tasks.create('MyWorker', {:client => 'Joe'})
148
+ ```
149
+
150
+
151
+ # The Rest of the IronWorker API
152
+
153
+ ## IronWorker::Client
154
+
155
+ You can use the `IronWorker::Client` class to upload code packages, queue tasks, create schedules, and more.
156
+
157
+ ### initialize(options = {})
158
+
159
+ Create a client object used for all your interactions with the IronWorker cloud.
160
+
161
+ ```ruby
162
+ client = IronWorker::Client.new(:token => 'IRON_IO_TOKEN', :project_id => 'IRON_IO_PROJECT_ID')
163
+ ```
164
+
165
+ ### codes.list(options = {})
166
+
167
+ Return an array of information about uploaded code packages. Visit http://dev.iron.io/worker/reference/api/#list_code_packages for more information about the available options and the code package object format.
168
+
169
+ ```ruby
170
+ client.codes.list.each do |code|
171
+ puts code.inspect
172
+ end
173
+ ```
174
+
175
+ ### codes.get(code_id)
176
+
177
+ Return information about an uploaded code package with the specified ID. Visit http://dev.iron.io/worker/reference/api/#get_info_about_a_code_package for more information about the code package object format.
178
+
179
+ ```ruby
180
+ puts client.codes.get('1234567890').name
181
+ ```
182
+
183
+ ### codes.create(code)
184
+
185
+ Upload an `IronWorker::Code::Ruby` object to the IronWorker cloud.
186
+
187
+ ```ruby
188
+ client.codes.create(code)
189
+ ```
190
+
191
+ ### codes.delete(code_id)
192
+
193
+ Delete the code package specified by `code_id` from the IronWorker cloud.
194
+
195
+ ```ruby
196
+ client.codes.delete('1234567890')
197
+ ```
198
+
199
+ ### codes.revisions(code_id, options = {})
200
+
201
+ Get an array of revision information for the code package specified by `code_id`. Visit http://dev.iron.io/worker/reference/api/#list_code_package_revisions for more information about the available options and the revision objects.
202
+
203
+ ```ruby
204
+ client.codes.revisions('1234567890').each do |revision|
205
+ puts revision.inspect
206
+ end
207
+ ```
208
+
209
+ ### codes.download(code_id, options = {})
210
+
211
+ Download the code package specified by `code_id` and return it as an array of bytes. Visit http://dev.iron.io/worker/reference/api/#download_a_code_package for more information about the available options.
212
+
213
+ ```ruby
214
+ data = client.codes.download('1234567890')
215
+ ```
216
+
217
+ ### tasks.list(options = {})
218
+
219
+ Retrieve an array of information about your workers' tasks. Visit http://dev.iron.io/worker/reference/api/#list_tasks for more information about the available options and the task object format.
220
+
221
+ ```ruby
222
+ client.tasks.list.each do |task|
223
+ puts task.inspect
224
+ end
225
+ ```
226
+
227
+ ### tasks.get(task_id)
228
+
229
+ Return information about the task specified by `task_id`. Visit http://dev.iron.io/worker/reference/api/#get_info_about_a_task for more information about the task object format.
230
+
231
+ ```ruby
232
+ puts client.tasks.get('1234567890').code_name
233
+ ```
234
+
235
+ ### tasks.create(code_name, params = {}, options = {})
236
+
237
+ Queue a new task for the code package specified by `code_name`, passing the `params` hash to it as a payload and returning a task object with only the `id` field filled. Visit http://dev.iron.io/worker/reference/api/#queue_a_task for more information about the available options.
238
+
239
+ ```ruby
240
+ task = client.tasks.create('MyWorker', {:client => 'Joe'}, {:delay => 180})
241
+ puts task.id
242
+ ```
243
+
244
+ ### tasks.cancel(task_id)
245
+
246
+ Cancel the task specified by `task_id`.
247
+
248
+ ```ruby
249
+ client.tasks.cancel('1234567890')
250
+ ```
251
+
252
+ ### tasks.cancel_all(code_id)
253
+
254
+ Cancel all tasks for the code package specified by `code_id`.
255
+
256
+ ```ruby
257
+ client.tasks.cancel_all('1234567890')
258
+ ```
259
+
260
+ ### tasks.log(task_id)
261
+
262
+ Retrieve the full task log for the task specified by `task_id`. Please note that log is available only after the task has completed execution. The log will include any output to `STDOUT`.
263
+
264
+ ```ruby
265
+ puts client.tasks.log('1234567890')
266
+ ```
267
+
268
+ ### tasks.set_progress(task_id, options = {})
269
+
270
+ Set the progress information for the task specified by `task_id`. This should be used from within workers to inform you about worker execution status, which you can retrieve with a `tasks.get` call. Visit http://dev.iron.io/worker/reference/api/#set_a_tasks_progress for more information about the available options.
271
+
272
+ ```ruby
273
+ client.tasks.set_progress('1234567890', {:msg => 'Still running...'})
274
+ ```
275
+
276
+ ### tasks.wait_for(task_id, options = {})
277
+
278
+ Wait (block) while the task specified by `task_id` executes. Options can contain a `:sleep` parameter used to modify the delay between API invocations; the default is 5 seconds. If a block is provided (as in the example below), it will be called after each API call with the task object as parameter.
279
+
280
+ ```ruby
281
+ client.tasks.wait_for('1234567890') do |task|
282
+ puts task.msg
283
+ end
284
+ ```
285
+
286
+ ### schedules.list(options = {})
287
+
288
+ Return an array of scheduled tasks. Visit http://dev.iron.io/worker/reference/api/#list_scheduled_tasks for more information about the available options and the scheduled task object format.
289
+
290
+ ```ruby
291
+ client.schedules.list.each do |schedule|
292
+ puts schedule.inspect
293
+ end
294
+ ```
295
+
296
+ ### schedules.get(schedule_id)
297
+
298
+ Return information about the scheduled task specified by `schedule_id`. Visit http://dev.iron.io/worker/reference/api/#get_info_about_a_scheduled_task for more information about the scheduled task object format.
299
+
300
+ ```ruby
301
+ puts client.schedules.get('1234567890').last_run_time
302
+ ```
303
+
304
+ ### schedules.create(code_name, params = {}, options = {})
305
+
306
+ Create a new scheduled task for the code package specified by `code_name`, passing the params hash to it as a data payload and returning a scheduled task object with only the `id` field filled. Visit http://dev.iron.io/worker/reference/api/#schedule_a_task for more information about the available options.
307
+
308
+ ```ruby
309
+ schedule = client.schedules.create('MyWorker', {:client => 'Joe'}, {:start_at => Time.now + 3600, :run_every =>60, :priority => 0, :run_times => 100, :end_at: Time.now + 2592000, Time.now + 84600})
310
+ puts schedule.id
311
+ ```
312
+
313
+ #### Scheduling Options
314
+
315
+ - **run_every**: The amount of time, in seconds, between runs. By default, the task will only run once. run_every will return a 400 error if it is set to less than 60.
316
+ - **end_at**: The time tasks will stop being queued.
317
+ - **run_times**: The number of times a task will run.
318
+ - **priority**: Setting the priority of your job. Valid values are 0, 1, and 2. The default is 0. Higher values means tasks spend less time in the queue once they come off the schedule.
319
+ - **start_at**: The time the scheduled task should first be run.
320
+ - **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.
321
+ - **delay**: The number of seconds to delay before scheduling the tasks. Default is 0.
322
+ - **task_delay**: The number of seconds to delay before actually queuing the task. Default is 0.
323
+ - **label**: Optional label for adding custom labels to scheduled tasks.
324
+ - **cluster**: cluster name ex: "high-mem" or "dedicated". This is a premium feature for customers to have access to more powerful or custom built worker solutions. Dedicated worker clusters exist for users who want to reserve a set number of workers just for their queued tasks. If not set default is set to "default" which is the public IronWorker cluster.
325
+
326
+ ### schedules.update(schedule_id, options = {})
327
+
328
+ Update a scheduled task specified by id
329
+
330
+ ```ruby
331
+ client.schedules.update('545b3cb829acd33ea10016e4', {label: 'new_label'})
332
+ ```
333
+
334
+ Or you can update a scheduled task for your worker from the command line using:
335
+
336
+ iron_worker update schedule 545b3cb829acd33ea10016e4 -s '{"label": "new_label"}'
337
+
338
+ ### schedules.cancel(schedule_id)
339
+
340
+ Cancel the scheduled task specified by `schedule_id`.
341
+
342
+ ```ruby
343
+ client.schedules.cancel('1234567890')
344
+ ```
345
+
346
+ ### patch your worker using cli
347
+
348
+ If you have an uploaded worker named `super_code` with files `qux.rb, bar.rb, etc.` and want to replace the content of `bar.rb` with a local file `foo.rb`, `qux.rb` with `baz.rb` just run a command:
349
+
350
+ iron_worker patch super_code -p 'foo.rb=bar.rb,baz.rb=lib/qux.rb.rb,foo.rb,foo2.rb'
351
+
352
+ No need to pass the same two file names `foo.rb=foo.rb`, only one `foo.rb` would be enough. Normally the patched version is put in place of the originals.
data/iron_worker.gemspec CHANGED
@@ -3,8 +3,8 @@ require File.expand_path('../lib/iron_worker/version', __FILE__)
3
3
  Gem::Specification.new do |gem|
4
4
  gem.authors = ["Travis Reeder"]
5
5
  gem.email = ["travis@iron.io"]
6
- gem.description = "DEPRECATED!! Use iron_worker_ng now. The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io"
7
- gem.summary = "DEPRECATED!! Use iron_worker_ng now. The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io"
6
+ gem.description = "The official IronWorker gem for IronWorker by Iron.io. http://iron.io"
7
+ gem.summary = "The official IronWorker gem for IronWorker by Iron.io. http://iron.io"
8
8
  gem.homepage = "https://github.com/iron-io/iron_worker_ruby"
9
9
 
10
10
  gem.files = `git ls-files`.split($\)
@@ -17,11 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.required_rubygems_version = ">= 1.3.6"
18
18
  gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
19
19
  gem.add_runtime_dependency "iron_core", ">= 0.5.1"
20
-
21
- gem.add_runtime_dependency 'rubyzip'
22
- gem.add_runtime_dependency 'rest-client'
23
- gem.add_runtime_dependency 'rest'
24
- gem.add_runtime_dependency 'bundler'
20
+ gem.add_runtime_dependency 'rest', '>= 3.0.6'
25
21
 
26
22
  end
27
-
data/lib/iron_worker.rb CHANGED
@@ -1,58 +1,20 @@
1
- puts "WARNING: iron_worker gem is deprecated. Please use iron_worker_ng gem, more info at https://github.com/iron-io/iron_worker_ruby_ng"
1
+ require 'json'
2
2
 
3
- require_relative 'iron_worker/utils'
4
- require_relative 'iron_worker/service'
5
- require_relative 'iron_worker/base'
6
- require_relative 'iron_worker/config'
7
- require_relative 'iron_worker/used_in_worker'
8
-
9
- module IronWorker
10
- @@logger = Logger.new(STDOUT)
11
- @@logger.level = Logger::INFO
12
-
13
-
14
- class << self
15
- attr_accessor :config,
16
- :service
17
-
18
- def configure()
19
- yield(config)
20
- if config && config.token
21
- IronWorker.service ||= Service.new(config.token, :config=>config)
22
- else
23
- @@logger.warn "No token specified in configure, be sure to set it!"
24
- end
25
- end
26
-
27
- def config
28
- @config ||= Config.new
29
- end
30
-
31
- def logger
32
- @@logger
3
+ if (not ''.respond_to?(:start_with?)) or (not ''.respond_to?(:end_with?))
4
+ class ::String
5
+ def start_with?(prefix)
6
+ prefix = prefix.to_s
7
+ self[0, prefix.length] == prefix
33
8
  end
34
9
 
35
- def api_version
36
- 2
37
- end
38
-
39
- def is_local?
40
- !is_remote?
41
- end
42
-
43
- def is_remote?
44
- false
10
+ def end_with?(suffix)
11
+ suffix = suffix.to_s
12
+ self[-suffix.length, suffix.length] == suffix
45
13
  end
46
14
  end
47
-
48
15
  end
49
16
 
50
- if defined?(Rails)
51
- # puts 'Rails=' + Rails.inspect
52
- # puts 'vers=' + Rails::VERSION::MAJOR.inspect
53
- if Rails::VERSION::MAJOR == 2
54
- require_relative 'iron_worker/rails2_init.rb'
55
- else
56
- require_relative 'iron_worker/railtie'
57
- end
58
- end
17
+ require 'iron_worker/version'
18
+ require 'iron_worker/api_client'
19
+ require 'iron_worker/worker_helper'
20
+