iron_worker 2.3.16 → 2.3.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Rakefile +31 -0
- data/iron_worker.gemspec +27 -0
- data/lib/generators/iron_worker/templates/template_worker.erb +7 -0
- data/lib/iron_worker/service.rb +1 -1
- data/lib/iron_worker/version.rb +4 -0
- data/test/Gemfile +36 -0
- data/test/Gemfile.lock +169 -0
- data/test/README.md +5 -0
- data/test/batch_run.rb +121 -0
- data/test/config_sample.yml +13 -0
- data/test/models/cool_model.rb +7 -0
- data/test/models/db_model.rb +6 -0
- data/test/models/model_1.rb +16 -0
- data/test/models/model_2.rb +16 -0
- data/test/quick_run.rb +36 -0
- data/test/quick_schedule.rb +18 -0
- data/test/resources/something.yml +4 -0
- data/test/simple_script.rb +11 -0
- data/test/test_base.rb +79 -0
- data/test/test_database.rb +31 -0
- data/test/test_gems.rb +31 -0
- data/test/test_inheritance.rb +25 -0
- data/test/test_iron_worker.rb +194 -0
- data/test/test_merging.rb +51 -0
- data/test/test_non_worker_script.rb +14 -0
- data/test/test_rails.rb +35 -0
- data/test/test_scheduling.rb +74 -0
- data/test/test_scheduling_no_active_support.rb +37 -0
- data/test/test_service.rb +28 -0
- data/test/test_uploads.rb +30 -0
- data/test/test_webhooks.rb +45 -0
- data/test/v2quick.rb +29 -0
- data/test/workers/awesome_job.rb +26 -0
- data/test/workers/aws_s3_worker.rb +10 -0
- data/test/workers/big_data_worker.rb +15 -0
- data/test/workers/big_gems_worker.rb +35 -0
- data/test/workers/cool_worker.rb +14 -0
- data/test/workers/db_worker.rb +27 -0
- data/test/workers/fail_worker.rb +10 -0
- data/test/workers/gem_dependency_worker.rb +20 -0
- data/test/workers/hacker_worker.rb +65 -0
- data/test/workers/iw_test_worker.rb +22 -0
- data/test/workers/iw_test_worker_2.rb +53 -0
- data/test/workers/iw_test_worker_3.rb +17 -0
- data/test/workers/local_vs_remote_worker.rb +9 -0
- data/test/workers/merging_worker.rb +40 -0
- data/test/workers/mq_worker.rb +21 -0
- data/test/workers/one_line_worker.rb +10 -0
- data/test/workers/prawn_worker.rb +32 -0
- data/test/workers/progress_worker.rb +26 -0
- data/test/workers/qb_worker.rb +17 -0
- data/test/workers/rails_worker.rb +24 -0
- data/test/workers/rails_worker2.rb +12 -0
- data/test/workers/requiring_worker.rb +4 -0
- data/test/workers/running_back_worker.rb +7 -0
- data/test/workers/scheduled_worker.rb +15 -0
- data/test/workers/second_worker.rb +16 -0
- data/test/workers/third_worker.rb +6 -0
- data/test/workers/webhook_worker.rb +7 -0
- data/test/zip_vs_gzip.rb +26 -0
- metadata +146 -91
- data/VERSION.yml +0 -5
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe522253fc444a2aee1f6f474ec587d671c25e30
|
4
|
+
data.tar.gz: 7e71a9926f99b579e03a776a6337aa9ec46b7335
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75c288511be5d4ff6dc27a4f554435775004142da36980e01bc0c48d8a3a0000212a424b6a0726e20319e5e5d0fe02c06572348382fc5bb38e3bfd8682de27ef
|
7
|
+
data.tar.gz: a522f0b44e0e050aed2a697c5498f9de884fd77a72831d00262f78a8d9d4ebd9ccc8d0c773ca5c083aee952223a8a4e96be4c1a77e2d5a2744f82c0cde22018c
|
data/.gitignore
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#require "rubygems"
|
2
|
+
#require "bundler/setup"
|
3
|
+
|
4
|
+
require 'rake/dsl_definition' # temporary I think?
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'jeweler2'
|
7
|
+
|
8
|
+
Jeweler::Tasks.new do |gemspec|
|
9
|
+
gemspec.name = "iron_worker"
|
10
|
+
gemspec.summary = "The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io"
|
11
|
+
gemspec.description = "The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io"
|
12
|
+
gemspec.email = "travis@iron.io"
|
13
|
+
gemspec.homepage = "http://www.iron.io"
|
14
|
+
gemspec.authors = ["Travis Reeder"]
|
15
|
+
gemspec.files = FileList['VERSION.yml','init.rb', 'lib/**/*.rb', 'rails/**/*.rb']
|
16
|
+
gemspec.add_dependency 'zip'
|
17
|
+
gemspec.add_dependency 'rest-client'
|
18
|
+
gemspec.add_dependency 'rest'
|
19
|
+
gemspec.add_dependency 'bundler'
|
20
|
+
#gemspec.add_dependency 'typhoeus'
|
21
|
+
gemspec.required_ruby_version = '>= 1.9'
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
|
25
|
+
Rake::TestTask.new do |t|
|
26
|
+
t.libs << "test"
|
27
|
+
t.test_files = FileList['test/test*.rb']
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
data/iron_worker.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../lib/iron_worker/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Travis Reeder"]
|
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"
|
8
|
+
gem.homepage = "https://github.com/iron-io/iron_worker_ruby"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "iron_worker"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = IronWorker::VERSION
|
16
|
+
|
17
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
18
|
+
gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
19
|
+
gem.add_runtime_dependency "iron_core", ">= 0.5.1"
|
20
|
+
|
21
|
+
gem.add_runtime_dependency 'zip'
|
22
|
+
gem.add_runtime_dependency 'rest-client'
|
23
|
+
gem.add_runtime_dependency 'rest'
|
24
|
+
gem.add_runtime_dependency 'bundler'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
data/lib/iron_worker/service.rb
CHANGED
data/test/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# These are required for the tests
|
2
|
+
|
3
|
+
source 'http://rubygems.org'
|
4
|
+
|
5
|
+
gem 'iron_worker'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'rack'
|
9
|
+
gem 'test-unit'
|
10
|
+
gem 'minitest'
|
11
|
+
gem 'jeweler2'
|
12
|
+
gem 'zip'
|
13
|
+
gem 'rest'
|
14
|
+
gem 'typhoeus'
|
15
|
+
gem 'uber_config'
|
16
|
+
|
17
|
+
gem 'simple_record'
|
18
|
+
gem 'activesupport'
|
19
|
+
gem 'simple_record'
|
20
|
+
gem 'dropbox', '1.2.3'
|
21
|
+
gem 'pusher'
|
22
|
+
gem 'carrierwave'
|
23
|
+
gem 'aws-s3'
|
24
|
+
gem 'mechanize'
|
25
|
+
gem 'mail'
|
26
|
+
gem 'timecop'
|
27
|
+
gem 'fog'
|
28
|
+
gem 'logglier'
|
29
|
+
#gem 'mysql2'
|
30
|
+
gem 'mini_fb'
|
31
|
+
gem 'iron_mq'
|
32
|
+
gem 'prawn'
|
33
|
+
gem 'pdf-reader'
|
34
|
+
gem 'concur'
|
35
|
+
gem 'mechanize'
|
36
|
+
end
|
data/test/Gemfile.lock
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
Ascii85 (1.0.2)
|
5
|
+
activesupport (3.2.8)
|
6
|
+
i18n (~> 0.6)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
aws (2.5.8)
|
9
|
+
http_connection
|
10
|
+
http_connection
|
11
|
+
uuidtools
|
12
|
+
uuidtools
|
13
|
+
xml-simple
|
14
|
+
xml-simple
|
15
|
+
aws-s3 (0.6.3)
|
16
|
+
builder
|
17
|
+
mime-types
|
18
|
+
xml-simple
|
19
|
+
builder (3.1.4)
|
20
|
+
carrierwave (0.5.8)
|
21
|
+
activesupport (~> 3.0)
|
22
|
+
concur (1.0.0)
|
23
|
+
faraday
|
24
|
+
faraday
|
25
|
+
domain_name (0.5.4)
|
26
|
+
unf (~> 0.0.3)
|
27
|
+
dropbox (1.2.3)
|
28
|
+
json (>= 1.2.0)
|
29
|
+
mechanize (>= 1.0.0)
|
30
|
+
multipart-post (>= 1.0)
|
31
|
+
oauth (>= 0.3.6)
|
32
|
+
ethon (0.5.3)
|
33
|
+
ffi (~> 1.0.11)
|
34
|
+
mime-types (~> 1.18)
|
35
|
+
excon (0.16.7)
|
36
|
+
faraday (0.8.4)
|
37
|
+
multipart-post (~> 1.1)
|
38
|
+
ffi (1.0.11)
|
39
|
+
fog (1.7.0)
|
40
|
+
builder
|
41
|
+
excon (~> 0.14)
|
42
|
+
formatador (~> 0.2.0)
|
43
|
+
mime-types
|
44
|
+
multi_json (~> 1.0)
|
45
|
+
net-scp (~> 1.0.4)
|
46
|
+
net-ssh (>= 2.1.3)
|
47
|
+
nokogiri (~> 1.5.0)
|
48
|
+
ruby-hmac
|
49
|
+
formatador (0.2.4)
|
50
|
+
git (1.2.5)
|
51
|
+
hashery (2.0.1)
|
52
|
+
hashie (1.2.0)
|
53
|
+
http_connection (1.4.2)
|
54
|
+
i18n (0.6.1)
|
55
|
+
iron_core (0.4.3)
|
56
|
+
rest (>= 2.0.2)
|
57
|
+
iron_mq (2.1.3)
|
58
|
+
iron_core (>= 0.4.2)
|
59
|
+
iron_worker (2.3.15)
|
60
|
+
bundler
|
61
|
+
bundler
|
62
|
+
rest
|
63
|
+
rest
|
64
|
+
rest-client
|
65
|
+
rest-client
|
66
|
+
zip
|
67
|
+
zip
|
68
|
+
jeweler2 (2.0.9)
|
69
|
+
git (>= 1.2.5)
|
70
|
+
json (1.7.5)
|
71
|
+
logglier (0.2.8)
|
72
|
+
mail (2.4.4)
|
73
|
+
i18n (>= 0.4.0)
|
74
|
+
mime-types (~> 1.16)
|
75
|
+
treetop (~> 1.4.8)
|
76
|
+
mechanize (2.5.1)
|
77
|
+
domain_name (~> 0.5, >= 0.5.1)
|
78
|
+
mime-types (~> 1.17, >= 1.17.2)
|
79
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
80
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
81
|
+
nokogiri (~> 1.4)
|
82
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
83
|
+
webrobots (~> 0.0, >= 0.0.9)
|
84
|
+
mime-types (1.19)
|
85
|
+
mini_fb (1.2.0)
|
86
|
+
hashie
|
87
|
+
hashie
|
88
|
+
rest-client
|
89
|
+
rest-client
|
90
|
+
minitest (4.2.0)
|
91
|
+
multi_json (1.3.7)
|
92
|
+
multipart-post (1.1.5)
|
93
|
+
net-http-digest_auth (1.2.1)
|
94
|
+
net-http-persistent (2.8)
|
95
|
+
net-scp (1.0.4)
|
96
|
+
net-ssh (>= 1.99.1)
|
97
|
+
net-ssh (2.6.1)
|
98
|
+
nokogiri (1.5.5)
|
99
|
+
ntlm-http (0.1.1)
|
100
|
+
oauth (0.4.7)
|
101
|
+
pdf-reader (1.2.0)
|
102
|
+
Ascii85 (~> 1.0.0)
|
103
|
+
hashery (~> 2.0)
|
104
|
+
ruby-rc4
|
105
|
+
polyglot (0.3.3)
|
106
|
+
prawn (0.12.0)
|
107
|
+
pdf-reader (>= 0.9.0)
|
108
|
+
ttfunk (~> 1.0.2)
|
109
|
+
pusher (0.10.0)
|
110
|
+
multi_json (~> 1.0)
|
111
|
+
signature (~> 0.1.4)
|
112
|
+
rack (1.4.1)
|
113
|
+
rest (2.1.0)
|
114
|
+
net-http-persistent
|
115
|
+
rest-client (>= 0.3.0)
|
116
|
+
rest-client (1.6.7)
|
117
|
+
mime-types (>= 1.16)
|
118
|
+
ruby-hmac (0.4.0)
|
119
|
+
ruby-rc4 (0.1.5)
|
120
|
+
signature (0.1.4)
|
121
|
+
simple_record (2.2.0)
|
122
|
+
aws
|
123
|
+
concur
|
124
|
+
test-unit (2.5.2)
|
125
|
+
timecop (0.5.3)
|
126
|
+
treetop (1.4.12)
|
127
|
+
polyglot
|
128
|
+
polyglot (>= 0.3.1)
|
129
|
+
ttfunk (1.0.3)
|
130
|
+
typhoeus (0.5.1)
|
131
|
+
ethon (= 0.5.3)
|
132
|
+
uber_config (1.0.5)
|
133
|
+
unf (0.0.5)
|
134
|
+
unf_ext
|
135
|
+
unf_ext (0.0.5)
|
136
|
+
uuidtools (2.1.3)
|
137
|
+
webrobots (0.0.13)
|
138
|
+
xml-simple (1.1.2)
|
139
|
+
zip (2.0.2)
|
140
|
+
|
141
|
+
PLATFORMS
|
142
|
+
ruby
|
143
|
+
|
144
|
+
DEPENDENCIES
|
145
|
+
activesupport
|
146
|
+
aws-s3
|
147
|
+
carrierwave
|
148
|
+
concur
|
149
|
+
dropbox (= 1.2.3)
|
150
|
+
fog
|
151
|
+
iron_mq
|
152
|
+
iron_worker
|
153
|
+
jeweler2
|
154
|
+
logglier
|
155
|
+
mail
|
156
|
+
mechanize
|
157
|
+
mini_fb
|
158
|
+
minitest
|
159
|
+
pdf-reader
|
160
|
+
prawn
|
161
|
+
pusher
|
162
|
+
rack
|
163
|
+
rest
|
164
|
+
simple_record
|
165
|
+
test-unit
|
166
|
+
timecop
|
167
|
+
typhoeus
|
168
|
+
uber_config
|
169
|
+
zip
|
data/test/README.md
ADDED
data/test/batch_run.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/one_line_worker'
|
3
|
+
require_relative 'workers/merging_worker'
|
4
|
+
require_relative 'workers/progress_worker'
|
5
|
+
require_relative 'workers/mq_worker'
|
6
|
+
require 'concur'
|
7
|
+
#require_relative 'prawn_worker'
|
8
|
+
|
9
|
+
class BatchRun < TestBase
|
10
|
+
|
11
|
+
def test_concur_batch
|
12
|
+
|
13
|
+
old_log_level = IronWorker.logger.level
|
14
|
+
IronWorker.logger.level = Logger::INFO
|
15
|
+
|
16
|
+
clz = OneLineWorker
|
17
|
+
num_tasks = 100
|
18
|
+
|
19
|
+
worker = clz.new
|
20
|
+
worker.upload
|
21
|
+
|
22
|
+
jobs = []
|
23
|
+
executor = Concur::Executor.new_thread_pool_executor(20)
|
24
|
+
num_tasks.times do |i|
|
25
|
+
jobs << executor.execute do
|
26
|
+
begin
|
27
|
+
worker2 = clz.new
|
28
|
+
puts "queueing #{i}"
|
29
|
+
if clz == MqWorker
|
30
|
+
worker2.config = {:token=>IronWorker.config.token, :project_id=>IronWorker.config.project_id}
|
31
|
+
else
|
32
|
+
worker2.x = "hello payload #{i}"
|
33
|
+
end
|
34
|
+
response_hash = worker2.queue(:priority=>(@config[:priority] || 0))
|
35
|
+
puts "response_hash #{i} = " + response_hash.inspect
|
36
|
+
assert response_hash["msg"]
|
37
|
+
assert response_hash["status_code"]
|
38
|
+
assert response_hash["tasks"]
|
39
|
+
assert response_hash["status_code"] == 200
|
40
|
+
assert response_hash["tasks"][0]["id"].length == 24, "length is #{response_hash["tasks"][0]["id"].length}"
|
41
|
+
assert response_hash["tasks"][0]["id"] == worker2.task_id, "id in hash: #{response_hash["tasks"][0]["id"]}, task_id: #{worker2.task_id}. response was #{worker2.response.inspect}"
|
42
|
+
worker2
|
43
|
+
rescue => ex
|
44
|
+
puts "ERROR! #{ex.class.name}: #{ex.message} -- #{ex.backtrace.inspect}"
|
45
|
+
raise ex
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
sleep 10
|
52
|
+
|
53
|
+
completed_count = 0
|
54
|
+
errored_queuing_count = 0
|
55
|
+
error_count = 0
|
56
|
+
while jobs.size > 0
|
57
|
+
jobs.each_with_index do |f, i|
|
58
|
+
# p f
|
59
|
+
begin
|
60
|
+
t = f.get
|
61
|
+
# p t
|
62
|
+
puts i.to_s + ' task_id=' + t.task_id.to_s
|
63
|
+
status_response = t.status # worker.status(t["task_id"])
|
64
|
+
puts 'status ' + status_response["status"] + ' for ' + status_response.inspect
|
65
|
+
puts 'msg=' + status_response["msg"].to_s
|
66
|
+
if status_response["status"] == "complete" || status_response["status"] == "error"
|
67
|
+
if true || status_response["status"] == "error"
|
68
|
+
puts t.get_log
|
69
|
+
end
|
70
|
+
|
71
|
+
jobs.delete(f)
|
72
|
+
completed_count += 1
|
73
|
+
puts "#{completed_count} completed so far. #{jobs.size} left..."
|
74
|
+
if status_response["status"] == "error"
|
75
|
+
error_count += 1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
rescue => ex
|
79
|
+
puts 'error! ' + ex.class.name + ' -> ' + ex.message.to_s
|
80
|
+
puts ex.backtrace
|
81
|
+
errored_queuing_count += 1
|
82
|
+
jobs.delete(f)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
puts 'sleep'
|
86
|
+
sleep 2
|
87
|
+
puts 'done sleeping'
|
88
|
+
end
|
89
|
+
|
90
|
+
puts 'Total completed=' + completed_count.to_s
|
91
|
+
puts 'Total errored while queuing=' + errored_queuing_count.to_s
|
92
|
+
puts 'Total errored while running=' + error_count.to_s
|
93
|
+
|
94
|
+
executor.shutdown
|
95
|
+
|
96
|
+
#tasks = []
|
97
|
+
#1000.times do |i|
|
98
|
+
# puts "#{i}"
|
99
|
+
# worker = ProgressWorker.new
|
100
|
+
# #worker = OneLineWorker.new
|
101
|
+
# # worker = MergingWorker.new
|
102
|
+
# #worker = PrawnWorker.new
|
103
|
+
# worker.queue
|
104
|
+
# tasks << worker
|
105
|
+
#end
|
106
|
+
#
|
107
|
+
#tasks.each_with_index do |task, i|
|
108
|
+
# puts "#{i}"
|
109
|
+
# status = task.wait_until_complete
|
110
|
+
# p status
|
111
|
+
# puts "\n\n\nLOG START:"
|
112
|
+
# puts task.get_log
|
113
|
+
# puts "LOG END\n\n\n"
|
114
|
+
# assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
115
|
+
#end
|
116
|
+
IronWorker.logger.level = old_log_level
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
data/test/quick_run.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/one_line_worker'
|
3
|
+
require_relative 'workers/progress_worker'
|
4
|
+
require_relative 'workers/fail_worker'
|
5
|
+
|
6
|
+
class QuickRun < TestBase
|
7
|
+
|
8
|
+
def test_worker
|
9
|
+
tasks = []
|
10
|
+
1.times do |i|
|
11
|
+
puts "Queuing #{i}"
|
12
|
+
worker = OneLineWorker.new
|
13
|
+
worker.x = i
|
14
|
+
worker.queue
|
15
|
+
tasks << worker
|
16
|
+
end
|
17
|
+
|
18
|
+
tasks.each_with_index do |worker, i|
|
19
|
+
puts "Waiting for #{i}"
|
20
|
+
status = worker.wait_until_complete
|
21
|
+
puts "#{i} is complete."
|
22
|
+
p status
|
23
|
+
puts "error_class: #{status["error_class"]}"
|
24
|
+
puts "msg: #{status["msg"]}"
|
25
|
+
puts "percent: #{status["percent"]}"
|
26
|
+
puts "\n\n\nLOG START:"
|
27
|
+
log = worker.get_log
|
28
|
+
puts log
|
29
|
+
puts "LOG END\n\n\n"
|
30
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
31
|
+
assert log.include?("hello")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'one_line_worker'
|
3
|
+
require_relative 'merging_worker'
|
4
|
+
require_relative 'progress_worker'
|
5
|
+
#require_relative 'prawn_worker'
|
6
|
+
|
7
|
+
class QuickRun < TestBase
|
8
|
+
|
9
|
+
def test_scheduler_quick
|
10
|
+
worker = TestWorker.new
|
11
|
+
worker.schedule(:start_at=>10.seconds.from_now)
|
12
|
+
status = worker.wait_until_complete
|
13
|
+
assert status["status"] == "complete"
|
14
|
+
assert status["msg"].present?
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
gem 'test-unit'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'yaml'
|
7
|
+
require 'uber_config'
|
8
|
+
begin
|
9
|
+
require File.join(File.dirname(__FILE__), '../lib/iron_worker')
|
10
|
+
rescue Exception => ex
|
11
|
+
puts "Could NOT load current iron_worker: " + ex.message
|
12
|
+
raise ex
|
13
|
+
end
|
14
|
+
|
15
|
+
#IronWorker.logger.level = Logger::DEBUG
|
16
|
+
IronWorker.service=nil
|
17
|
+
IronWorker.config.merged_gems={}
|
18
|
+
|
19
|
+
|
20
|
+
require_relative "workers/iw_test_worker"
|
21
|
+
require_relative "workers/iw_test_worker_2"
|
22
|
+
require_relative "workers/iw_test_worker_3"
|
23
|
+
|
24
|
+
class TestBase < Test::Unit::TestCase
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@config = UberConfig.load
|
28
|
+
puts "config: " + @config.inspect
|
29
|
+
raise "Config is nil! Ensure you have a config file in the proper place." if @config.nil?
|
30
|
+
|
31
|
+
@token = @config['iron']['token']
|
32
|
+
@project_id = @config['iron']['project_id']
|
33
|
+
puts "@token: #{@token}"
|
34
|
+
# new style
|
35
|
+
IronWorker.configure do |config|
|
36
|
+
config.token = @token
|
37
|
+
config.project_id = @project_id
|
38
|
+
config.host = @config['iron']['host'] if @config['iron']['host']
|
39
|
+
config.port = @config['iron']['port'] if @config['iron']['port']
|
40
|
+
config.scheme = @config['iron']['scheme'] if @config['iron']['scheme']
|
41
|
+
config.global_attributes["db_user"] = "sa"
|
42
|
+
config.global_attributes["db_pass"] = "pass"
|
43
|
+
#config.database = @config["database"]
|
44
|
+
config.force_upload = true
|
45
|
+
# config.skip_auto_dependencies = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def puts_log(worker)
|
50
|
+
puts "LOG START:"
|
51
|
+
puts worker.get_log
|
52
|
+
puts ":LOG END"
|
53
|
+
end
|
54
|
+
|
55
|
+
def wait_for_task(params={})
|
56
|
+
tries = 0
|
57
|
+
status = nil
|
58
|
+
sleep 1
|
59
|
+
while tries < 60
|
60
|
+
status = status_for(params)
|
61
|
+
puts "status: #{status['status']} -- " + status.inspect
|
62
|
+
if status["status"] == "complete" || status["status"] == "error"
|
63
|
+
break
|
64
|
+
end
|
65
|
+
sleep 2
|
66
|
+
end
|
67
|
+
status
|
68
|
+
end
|
69
|
+
|
70
|
+
def status_for(ob)
|
71
|
+
if ob.is_a?(Hash)
|
72
|
+
ob[:schedule_id] ? WORKER.schedule_status(ob[:schedule_id]) : WORKER.status(ob[:task_id])
|
73
|
+
else
|
74
|
+
ob.status
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/db_worker'
|
3
|
+
require_relative 'models/db_model'
|
4
|
+
class IronWorkerTests < TestBase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
IronWorker.config.database = @config['database']
|
9
|
+
end
|
10
|
+
|
11
|
+
#def test_active_record
|
12
|
+
# dbw = DbWorker.new
|
13
|
+
# dbw.run_local
|
14
|
+
# assert !dbw.ob.nil?
|
15
|
+
# assert !dbw.ob.id.nil?
|
16
|
+
#
|
17
|
+
# dbw.queue
|
18
|
+
# # would be interesting if the object could update itself on complete. Like it would retrieve new values from
|
19
|
+
# # finished job when calling status or something.
|
20
|
+
#
|
21
|
+
# status = wait_for_task(dbw)
|
22
|
+
# puts 'status: ' + status.inspect
|
23
|
+
# puts "\n\n\nLOG START:"
|
24
|
+
# puts dbw.get_log
|
25
|
+
# puts "LOG END\n\n\n"
|
26
|
+
# assert status["status"] == "complete"
|
27
|
+
#
|
28
|
+
#
|
29
|
+
#end
|
30
|
+
|
31
|
+
end
|