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
data/test/test_gems.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/awesome_job'
|
3
|
+
require_relative 'workers/aws_s3_worker'
|
4
|
+
|
5
|
+
class TestGems < TestBase
|
6
|
+
|
7
|
+
def test_dropbox_gem
|
8
|
+
|
9
|
+
worker = AwesomeJob.new
|
10
|
+
worker.queue
|
11
|
+
|
12
|
+
worker.wait_until_complete
|
13
|
+
|
14
|
+
puts 'log=' + worker.get_log
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_aws_s3_gem
|
19
|
+
|
20
|
+
worker = AwsS3Worker.new
|
21
|
+
puts 'run_local'
|
22
|
+
worker.run_local
|
23
|
+
worker.queue
|
24
|
+
|
25
|
+
worker.wait_until_complete
|
26
|
+
|
27
|
+
puts 'log=' + worker.get_log
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
|
3
|
+
class TestInheritance < TestBase
|
4
|
+
|
5
|
+
def test_who_am_i
|
6
|
+
|
7
|
+
worker = TestWorker2.new
|
8
|
+
puts "1: " + worker.who_am_i?
|
9
|
+
puts "2: " + worker.who_am_i2?
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_multi_subs
|
15
|
+
t3 = TestWorker3.new
|
16
|
+
t3.queue
|
17
|
+
t3.wait_until_complete
|
18
|
+
puts "LOG:"
|
19
|
+
log = t3.get_log
|
20
|
+
puts log
|
21
|
+
assert log.include?("super_class_method")
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/cool_worker'
|
3
|
+
require_relative 'models/cool_model'
|
4
|
+
require_relative 'workers/gem_dependency_worker'
|
5
|
+
require_relative 'workers/fail_worker'
|
6
|
+
require_relative 'workers/progress_worker'
|
7
|
+
require_relative 'workers/one_line_worker'
|
8
|
+
require_relative 'workers/big_gems_worker'
|
9
|
+
require_relative 'workers/webhook_worker'
|
10
|
+
require_relative 'workers/local_vs_remote_worker'
|
11
|
+
|
12
|
+
class IronWorkerTests < TestBase
|
13
|
+
|
14
|
+
# todo: test both gems
|
15
|
+
#def test_rest_client
|
16
|
+
# Uber.gem = :rest_client
|
17
|
+
#
|
18
|
+
# worker = OneLineWorker.new
|
19
|
+
# worker.queue
|
20
|
+
#
|
21
|
+
# IronWorker.service.host = "http://www.wlajdfljalsjfklsldf.com/"
|
22
|
+
# IronWorker.service.reset_base_url
|
23
|
+
#
|
24
|
+
# status = worker.wait_until_complete
|
25
|
+
# p status
|
26
|
+
# p status["error_class"]
|
27
|
+
# p status["msg"]
|
28
|
+
# puts "\n\n\nLOG START:"
|
29
|
+
# log = worker.get_log
|
30
|
+
# puts log
|
31
|
+
# puts "LOG END\n\n\n"
|
32
|
+
# assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
33
|
+
# Uber.gem = :typhoeus
|
34
|
+
#end
|
35
|
+
|
36
|
+
|
37
|
+
def test_old_gem_error_message
|
38
|
+
assert_raise do
|
39
|
+
IronWorker.config.access_key = "abc"
|
40
|
+
end
|
41
|
+
assert_raise do
|
42
|
+
assert_raise IronWorker.config.secret_key = "abc"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_gem_merging
|
47
|
+
worker = GemDependencyWorker.new
|
48
|
+
worker.queue
|
49
|
+
status = worker.wait_until_complete
|
50
|
+
p status
|
51
|
+
puts_log(worker)
|
52
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_new_worker_style
|
56
|
+
# Add something to queue, get task ID back
|
57
|
+
tw = TestWorker2.new
|
58
|
+
tw.s3_key = "active style runner"
|
59
|
+
tw.times = 3
|
60
|
+
tw.x = true
|
61
|
+
|
62
|
+
# queue up a task
|
63
|
+
puts 'queuing ' + tw.inspect
|
64
|
+
|
65
|
+
response_hash = nil
|
66
|
+
5.times do |i|
|
67
|
+
response_hash = tw.queue
|
68
|
+
end
|
69
|
+
|
70
|
+
puts 'response_hash=' + response_hash.inspect
|
71
|
+
puts 'task_id=' + tw.task_id
|
72
|
+
|
73
|
+
assert response_hash["msg"]
|
74
|
+
assert response_hash["tasks"]
|
75
|
+
assert response_hash["tasks"][0]["id"].length == 24, "length is #{response_hash["tasks"][0]["id"].length}"
|
76
|
+
assert response_hash["tasks"][0]["id"] == tw.task_id
|
77
|
+
|
78
|
+
status = tw.wait_until_complete
|
79
|
+
|
80
|
+
puts 'LOG=' + tw.get_log
|
81
|
+
assert tw.status["status"] == "complete"
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_global_attributes
|
86
|
+
worker = TestWorker3.new
|
87
|
+
worker.run_local
|
88
|
+
|
89
|
+
puts 'worker=' + worker.inspect
|
90
|
+
|
91
|
+
assert_equal "sa", worker.db_user
|
92
|
+
assert_equal "pass", worker.db_pass
|
93
|
+
assert_equal 123, worker.x
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def test_data_passing
|
99
|
+
cool = CoolWorker.new
|
100
|
+
cool.array_of_models = [CoolModel.new(:name => "name1"), CoolModel.new(:name => "name2")]
|
101
|
+
cool.queue
|
102
|
+
status = cool.wait_until_complete
|
103
|
+
assert status["status"] == "complete"
|
104
|
+
log = IronWorker.service.log(cool.task_id)
|
105
|
+
puts 'log=' + log.inspect
|
106
|
+
assert log.length > 10
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_set_progress
|
111
|
+
worker = TestWorker.new
|
112
|
+
worker.s3_key = "abc"
|
113
|
+
worker.times = 10
|
114
|
+
worker.queue
|
115
|
+
status = worker.wait_until_complete
|
116
|
+
p status
|
117
|
+
log = worker.get_log
|
118
|
+
puts 'log: ' + log
|
119
|
+
puts 'STATUS: ' + status.inspect
|
120
|
+
assert log.include?("running at 5")
|
121
|
+
assert status["status"] == "complete"
|
122
|
+
assert status["percent"] > 0
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_exceptions
|
127
|
+
worker = FailWorker.new
|
128
|
+
worker.queue
|
129
|
+
status = worker.wait_until_complete
|
130
|
+
assert status["status"] == "error"
|
131
|
+
assert status["msg"].present?
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def test_progress
|
136
|
+
worker = ProgressWorker.new
|
137
|
+
worker.s3_key = "YOOOOO"
|
138
|
+
worker.queue
|
139
|
+
|
140
|
+
status = worker.wait_until_complete
|
141
|
+
p status
|
142
|
+
p status["error_class"]
|
143
|
+
p status["msg"]
|
144
|
+
puts "\n\n\nLOG START:"
|
145
|
+
log = worker.get_log
|
146
|
+
puts log
|
147
|
+
puts "LOG END\n\n\n"
|
148
|
+
puts "Status:"
|
149
|
+
puts status
|
150
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
151
|
+
assert log.include?(worker.s3_key)
|
152
|
+
#assert status["percent"]
|
153
|
+
#assert status["percent"] > 0
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_big_gems_worker
|
157
|
+
|
158
|
+
#raise "BigGemWorker DOESN'T WORK, remove this raise when fixed."
|
159
|
+
|
160
|
+
worker = BigGemsWorker.new
|
161
|
+
worker.queue
|
162
|
+
|
163
|
+
status = worker.wait_until_complete
|
164
|
+
p status
|
165
|
+
p status["error_class"]
|
166
|
+
p status["msg"]
|
167
|
+
puts "\n\n\nLOG START:"
|
168
|
+
log = worker.get_log
|
169
|
+
puts log
|
170
|
+
puts "LOG END\n\n\n"
|
171
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
172
|
+
assert log.include?("hello")
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def test_local_vs_remote
|
177
|
+
|
178
|
+
worker = LocalVsRemoteWorker.new
|
179
|
+
worker.run_local
|
180
|
+
assert worker.is_local?
|
181
|
+
# now remote
|
182
|
+
worker.queue
|
183
|
+
|
184
|
+
status = worker.wait_until_complete
|
185
|
+
p status
|
186
|
+
log = worker.get_log
|
187
|
+
puts 'log: ' + log
|
188
|
+
puts 'STATUS: ' + status.inspect
|
189
|
+
assert status["status"] == "complete"
|
190
|
+
assert log.include?("is_remote? true")
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
#require 'active_record'
|
3
|
+
require_relative 'workers/cool_worker'
|
4
|
+
require_relative 'models/cool_model'
|
5
|
+
require_relative 'models/db_model'
|
6
|
+
require_relative 'workers/prawn_worker'
|
7
|
+
|
8
|
+
class TestMerging < TestBase
|
9
|
+
|
10
|
+
def test_merge_worker
|
11
|
+
tw = TestWorker2.new
|
12
|
+
tw.s3_key = "active style runner"
|
13
|
+
tw.times = 3
|
14
|
+
tw.x = true
|
15
|
+
|
16
|
+
response_hash_single = nil
|
17
|
+
5.times do |i|
|
18
|
+
begin
|
19
|
+
response_hash_single = tw.queue
|
20
|
+
rescue => ex
|
21
|
+
puts ex.message
|
22
|
+
raise ex
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
puts 'response_hash=' + response_hash_single.inspect
|
27
|
+
puts 'task_id=' + tw.task_id
|
28
|
+
status = tw.wait_until_complete
|
29
|
+
puts 'log=' + tw.get_log
|
30
|
+
assert tw.status["status"] == "complete"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_include_dirs
|
34
|
+
worker = PrawnWorker.new
|
35
|
+
worker.queue
|
36
|
+
|
37
|
+
status = worker.wait_until_complete
|
38
|
+
p status
|
39
|
+
puts "\n\n\nLOG START:"
|
40
|
+
l = worker.get_log
|
41
|
+
puts l
|
42
|
+
puts "LOG END\n\n\n"
|
43
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
44
|
+
assert l.include?("hello.pdf")
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_merge_mailer
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
## This is a test for running a simple ruby script, not using the Base class.
|
2
|
+
#require_relative 'test_base'
|
3
|
+
#
|
4
|
+
#class ScriptTest < TestBase
|
5
|
+
#
|
6
|
+
# def test_script
|
7
|
+
# IronWorker.service.upload "one_line_worker.rb", "OneLineWorker"
|
8
|
+
# queue_result = IronWorker.service.queue "simple_script_name", 'x'=>"attribute x"
|
9
|
+
# status = IronWorker.service.wait_until_complete(queue_result)
|
10
|
+
# assert status["status"] = "complete"
|
11
|
+
# # todo: assert log contains our x attribute value
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
#end
|
data/test/test_rails.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/rails_worker'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
def self.env
|
7
|
+
"superenviro"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
"3.0.1"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class RailsTests < TestBase
|
16
|
+
|
17
|
+
def test_env
|
18
|
+
worker = RailsWorker.new
|
19
|
+
worker.queue(:priority => 2)
|
20
|
+
|
21
|
+
status = worker.wait_until_complete
|
22
|
+
p status
|
23
|
+
p status["error_class"]
|
24
|
+
p status["msg"]
|
25
|
+
assert status["status"] == "complete", "Status was not complete, it was #{status["status"]}"
|
26
|
+
puts "\n\n\nLOG START:"
|
27
|
+
log = worker.get_log
|
28
|
+
puts log
|
29
|
+
puts "LOG END\n\n\n"
|
30
|
+
assert log.include?("env=" + Rails.env)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/one_line_worker'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
class IronWorkerTests < TestBase
|
6
|
+
|
7
|
+
def test_scheduler
|
8
|
+
worker = OneLineWorker.new
|
9
|
+
|
10
|
+
start_time = Time.now
|
11
|
+
worker.schedule(:start_at=>30.seconds.from_now)
|
12
|
+
status = worker.wait_until_complete
|
13
|
+
assert status["status"] == "complete"
|
14
|
+
end_time = Time.now
|
15
|
+
duration = (end_time-start_time)
|
16
|
+
puts "duration=#{duration}"
|
17
|
+
assert duration > 28
|
18
|
+
|
19
|
+
worker = OneLineWorker.new
|
20
|
+
worker.schedule(:start_at=>1.seconds.from_now, :run_every=>60, :end_at=>(6*60).seconds.from_now)
|
21
|
+
status = worker.wait_until_complete
|
22
|
+
assert status["status"] == "complete"
|
23
|
+
puts "run_count=#{status["run_count"]}"
|
24
|
+
assert status["run_count"] > 5
|
25
|
+
assert status["run_count"] < 20
|
26
|
+
|
27
|
+
worker = OneLineWorker.new
|
28
|
+
worker.schedule(:start_at => 2.seconds.since, :run_every => 60, :run_times => 5)
|
29
|
+
status = worker.wait_until_complete
|
30
|
+
assert status["status"] == "complete"
|
31
|
+
puts "run_count=#{status["run_count"]}"
|
32
|
+
assert status["run_count"] == 5
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_schedule_cancel
|
36
|
+
puts 'test_schedule_cancel'
|
37
|
+
worker = OneLineWorker.new
|
38
|
+
worker.schedule(start_at: 30.seconds.from_now)
|
39
|
+
p worker
|
40
|
+
IronWorker.service.cancel_schedule(worker.schedule_id)
|
41
|
+
assert_equal worker.status['status'], 'cancelled'
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_schedules_paging
|
45
|
+
puts 'test_schedule_cancel'
|
46
|
+
1.times do |i|
|
47
|
+
worker = OneLineWorker.new
|
48
|
+
worker.schedule(start_at: 30.seconds.from_now)
|
49
|
+
p worker
|
50
|
+
end
|
51
|
+
sleep 1
|
52
|
+
page = 0
|
53
|
+
while page <= 100
|
54
|
+
puts "page #{page}"
|
55
|
+
schedules = IronWorker.service.schedules(:page=>page)['schedules']
|
56
|
+
page += 1
|
57
|
+
puts 'schedules=' + schedules.inspect
|
58
|
+
puts 'schedules.size=' + schedules.size.to_s
|
59
|
+
if schedules.size == 0
|
60
|
+
return
|
61
|
+
end
|
62
|
+
schedules.each do |s|
|
63
|
+
puts "schedule: #{s['id']} #{s['status']}"
|
64
|
+
if s['status'] != 'scheduled'
|
65
|
+
next
|
66
|
+
end
|
67
|
+
puts 'SCHEDULED!! Cancelling...'
|
68
|
+
IronWorker.service.cancel_schedule(s['id'])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/one_line_worker'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
class IronWorkerTests < TestBase
|
6
|
+
|
7
|
+
def test_scheduler_no_as
|
8
|
+
worker = OneLineWorker.new
|
9
|
+
|
10
|
+
start_time = Time.now
|
11
|
+
worker.schedule(:start_at=>(Time.now + 30).iso8601)
|
12
|
+
status = worker.wait_until_complete
|
13
|
+
assert status["status"] == "complete"
|
14
|
+
end_time = Time.now
|
15
|
+
duration = (end_time-start_time)
|
16
|
+
puts "duration=#{duration}"
|
17
|
+
assert duration > 28
|
18
|
+
|
19
|
+
worker = OneLineWorker.new
|
20
|
+
worker.schedule(:start_at=>Time.now.iso8601, :run_every=>60, :end_at=>(Time.now + (60*5)).iso8601)
|
21
|
+
status = worker.wait_until_complete
|
22
|
+
assert status["status"] == "complete"
|
23
|
+
puts "run_count=#{status["run_count"]}"
|
24
|
+
assert status["run_count"] > 4
|
25
|
+
assert status["run_count"] < 10
|
26
|
+
|
27
|
+
worker = OneLineWorker.new
|
28
|
+
worker.schedule(:start_at => Time.now.iso8601, :run_every => 60, :run_times => 5)
|
29
|
+
status = worker.wait_until_complete
|
30
|
+
assert status["status"] == "complete"
|
31
|
+
puts "run_count=#{status["run_count"]}"
|
32
|
+
assert status["run_count"] == 5
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
|
3
|
+
class ServiceTests < TestBase
|
4
|
+
|
5
|
+
def test_codes
|
6
|
+
resp = IronWorker.service.codes
|
7
|
+
p resp
|
8
|
+
assert resp["codes"]
|
9
|
+
assert resp["codes"].is_a?(Array)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_tasks
|
13
|
+
resp = IronWorker.service.tasks
|
14
|
+
p resp
|
15
|
+
assert resp["tasks"]
|
16
|
+
assert resp["tasks"].is_a?(Array)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_schedules
|
20
|
+
resp = IronWorker.service.schedules
|
21
|
+
p resp
|
22
|
+
assert resp["schedules"]
|
23
|
+
assert resp["schedules"].is_a?(Array)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
|
3
|
+
class IronWorkerTests < TestBase
|
4
|
+
|
5
|
+
#def test_uploads
|
6
|
+
# IronWorker.config.force_upload = false
|
7
|
+
# IronWorker.config.no_upload = true
|
8
|
+
#
|
9
|
+
# gen_worker
|
10
|
+
#
|
11
|
+
# IronWorker.config.no_upload = nil
|
12
|
+
# IronWorker.config.force_upload = true
|
13
|
+
#
|
14
|
+
# gen_worker
|
15
|
+
#
|
16
|
+
#end
|
17
|
+
#
|
18
|
+
#def gen_worker
|
19
|
+
# # copy our simplest worker
|
20
|
+
# new_file = "one_line_worker_#{Random.rand(100)}.rb"
|
21
|
+
# FileUtils.cp('workers/one_line_worker.rb', new_file)
|
22
|
+
# load new_file
|
23
|
+
#
|
24
|
+
# w = OneLineWorker.new
|
25
|
+
# w.queue
|
26
|
+
#end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'workers/webhook_worker'
|
3
|
+
|
4
|
+
|
5
|
+
class TestWebhooks < TestBase
|
6
|
+
|
7
|
+
def test_webhook
|
8
|
+
worker = WebhookWorker.new
|
9
|
+
worker.upload
|
10
|
+
|
11
|
+
code_name = worker.class.name
|
12
|
+
payload = "webhooked!"
|
13
|
+
|
14
|
+
# Now we hit the webhook
|
15
|
+
@uber_client = Rest::Client.new
|
16
|
+
puts 'TOKEN??? WTF?? ' + @token.inspect
|
17
|
+
url = "#{IronWorker.service.base_url}/projects/#{@project_id}/tasks/webhook?code_name=#{code_name}&oauth=#{@token}"
|
18
|
+
p url
|
19
|
+
resp = @uber_client.post(url, {:body => payload})
|
20
|
+
p resp
|
21
|
+
body = JSON.parse(resp.body)
|
22
|
+
p body
|
23
|
+
|
24
|
+
@task_id = body["id"]
|
25
|
+
|
26
|
+
url = "#{IronWorker.service.base_url}/projects/#{@project_id}/tasks/#{@task_id}?oauth=#{@token}"
|
27
|
+
p url
|
28
|
+
resp = @uber_client.get(url)
|
29
|
+
p resp
|
30
|
+
|
31
|
+
status = IronWorker.service.wait_until_complete(@task_id)
|
32
|
+
p status
|
33
|
+
assert status["status"]
|
34
|
+
puts status["msg"]
|
35
|
+
|
36
|
+
puts "LOG:"
|
37
|
+
log = IronWorker.service.get_log(@task_id)
|
38
|
+
puts log
|
39
|
+
assert log.include?(payload)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
data/test/v2quick.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'test_base'
|
2
|
+
require_relative 'one_line_worker'
|
3
|
+
|
4
|
+
class QuickRun < TestBase
|
5
|
+
|
6
|
+
def test_worker
|
7
|
+
|
8
|
+
scheds = IronWorker.service.schedules(:project_id=>"4e71843298ea9b6b9f000004")
|
9
|
+
puts scheds.inspect
|
10
|
+
|
11
|
+
jobs = IronWorker.service.jobs(:project_id=>"4e71843298ea9b6b9f000004")
|
12
|
+
puts jobs.inspect
|
13
|
+
|
14
|
+
workers = IronWorker.service.code(:project_id=>"4e71843298ea9b6b9f000004")
|
15
|
+
puts workers.inspect
|
16
|
+
|
17
|
+
worker = OneLineWorker.new
|
18
|
+
res = worker.queue(:project_id=>"4e71843298ea9b6b9f000004")
|
19
|
+
puts "worker.queue returns: " + res.inspect
|
20
|
+
job_id = res["task_id"]
|
21
|
+
|
22
|
+
sleep 10
|
23
|
+
|
24
|
+
log = worker.get_log(:project_id=>"4e71843298ea9b6b9f000004")
|
25
|
+
puts log.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# bump..
|
2
|
+
class AwesomeJob < IronWorker::Base
|
3
|
+
merge_gem 'dropbox'
|
4
|
+
|
5
|
+
# todo: this one causes a stack level too deep error??
|
6
|
+
# merge_gem 'mongoid_i18n', :require => 'mongoid/i18n'
|
7
|
+
|
8
|
+
def run
|
9
|
+
begin
|
10
|
+
s = Dropbox::Session.new('...', '...')
|
11
|
+
rescue => ex
|
12
|
+
log "Dropbox doesn't like it when you don't have keys"
|
13
|
+
end
|
14
|
+
# s.mode = :dropbox
|
15
|
+
# s.authorizing_user = 'email@gmail.com'
|
16
|
+
# s.authorizing_password = '...'
|
17
|
+
# s.authorize!
|
18
|
+
#
|
19
|
+
# tmp_file = Tempfile.new('myfile.txt')
|
20
|
+
# tmp_file.write("blahblah")
|
21
|
+
# tmp_file.close
|
22
|
+
#
|
23
|
+
# s.upload tmp_file.path, 'Test'
|
24
|
+
# tmp_file.unlink
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# bump......
|
2
|
+
class BigDataWorker < IronWorker::Base
|
3
|
+
|
4
|
+
attr_accessor :x
|
5
|
+
|
6
|
+
def run
|
7
|
+
puts "hello world! #{x}"
|
8
|
+
sleep_for = 30
|
9
|
+
puts "sleeping for #{sleep_for} seconds..."
|
10
|
+
sleep sleep_for
|
11
|
+
puts "Done sleeping and done working."
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
RMAGICK_BYPASS_VERSION_TEST = true
|
3
|
+
|
4
|
+
class BigGemsWorker < IronWorker::Base
|
5
|
+
attr_accessor :x
|
6
|
+
#
|
7
|
+
#merge_gem 'activesupport', {:version => '3.1.3', :require=>'active_support/core_ext'}
|
8
|
+
##merge_gem 'railties', {:version => '3.1.3', :require => 'rails'}
|
9
|
+
#require 'mysql2'
|
10
|
+
#merge_gem 'activemodel', {:version => '3.1.3', :require=>'active_model'}
|
11
|
+
#merge_gem 'activemodel', {:version => '3.1.3', :require=>'active_model/secure_password'}
|
12
|
+
#
|
13
|
+
#merge_gem 'activerecord', {:version => '3.1.3', :require=>'active_record'}
|
14
|
+
#merge_gem 'actionmailer', {:version => '3.1.3', :require=>'action_mailer'}
|
15
|
+
#merge_gem 'actionpack', {:version => '3.1.3', :require => 'action_pack'}
|
16
|
+
#require 'RMagick'
|
17
|
+
#
|
18
|
+
merge_gem 'timecop'
|
19
|
+
#
|
20
|
+
#
|
21
|
+
#merge_gem 'carrierwave', {:version => '0.5.8', :require => ['carrierwave', 'carrierwave/orm/activerecord']}
|
22
|
+
merge_gem 'fog'
|
23
|
+
##merge_gem 'friendly_id', {:version => '4.0.0.beta14'}
|
24
|
+
|
25
|
+
merge_gem 'concur'
|
26
|
+
|
27
|
+
merge_gem 'mechanize'
|
28
|
+
#unmerge_gem 'nokogiri'
|
29
|
+
|
30
|
+
merge_gem 'mail'
|
31
|
+
|
32
|
+
def run
|
33
|
+
log "hello"
|
34
|
+
end
|
35
|
+
end
|