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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/Rakefile +31 -0
  4. data/iron_worker.gemspec +27 -0
  5. data/lib/generators/iron_worker/templates/template_worker.erb +7 -0
  6. data/lib/iron_worker/service.rb +1 -1
  7. data/lib/iron_worker/version.rb +4 -0
  8. data/test/Gemfile +36 -0
  9. data/test/Gemfile.lock +169 -0
  10. data/test/README.md +5 -0
  11. data/test/batch_run.rb +121 -0
  12. data/test/config_sample.yml +13 -0
  13. data/test/models/cool_model.rb +7 -0
  14. data/test/models/db_model.rb +6 -0
  15. data/test/models/model_1.rb +16 -0
  16. data/test/models/model_2.rb +16 -0
  17. data/test/quick_run.rb +36 -0
  18. data/test/quick_schedule.rb +18 -0
  19. data/test/resources/something.yml +4 -0
  20. data/test/simple_script.rb +11 -0
  21. data/test/test_base.rb +79 -0
  22. data/test/test_database.rb +31 -0
  23. data/test/test_gems.rb +31 -0
  24. data/test/test_inheritance.rb +25 -0
  25. data/test/test_iron_worker.rb +194 -0
  26. data/test/test_merging.rb +51 -0
  27. data/test/test_non_worker_script.rb +14 -0
  28. data/test/test_rails.rb +35 -0
  29. data/test/test_scheduling.rb +74 -0
  30. data/test/test_scheduling_no_active_support.rb +37 -0
  31. data/test/test_service.rb +28 -0
  32. data/test/test_uploads.rb +30 -0
  33. data/test/test_webhooks.rb +45 -0
  34. data/test/v2quick.rb +29 -0
  35. data/test/workers/awesome_job.rb +26 -0
  36. data/test/workers/aws_s3_worker.rb +10 -0
  37. data/test/workers/big_data_worker.rb +15 -0
  38. data/test/workers/big_gems_worker.rb +35 -0
  39. data/test/workers/cool_worker.rb +14 -0
  40. data/test/workers/db_worker.rb +27 -0
  41. data/test/workers/fail_worker.rb +10 -0
  42. data/test/workers/gem_dependency_worker.rb +20 -0
  43. data/test/workers/hacker_worker.rb +65 -0
  44. data/test/workers/iw_test_worker.rb +22 -0
  45. data/test/workers/iw_test_worker_2.rb +53 -0
  46. data/test/workers/iw_test_worker_3.rb +17 -0
  47. data/test/workers/local_vs_remote_worker.rb +9 -0
  48. data/test/workers/merging_worker.rb +40 -0
  49. data/test/workers/mq_worker.rb +21 -0
  50. data/test/workers/one_line_worker.rb +10 -0
  51. data/test/workers/prawn_worker.rb +32 -0
  52. data/test/workers/progress_worker.rb +26 -0
  53. data/test/workers/qb_worker.rb +17 -0
  54. data/test/workers/rails_worker.rb +24 -0
  55. data/test/workers/rails_worker2.rb +12 -0
  56. data/test/workers/requiring_worker.rb +4 -0
  57. data/test/workers/running_back_worker.rb +7 -0
  58. data/test/workers/scheduled_worker.rb +15 -0
  59. data/test/workers/second_worker.rb +16 -0
  60. data/test/workers/third_worker.rb +6 -0
  61. data/test/workers/webhook_worker.rb +7 -0
  62. data/test/zip_vs_gzip.rb +26 -0
  63. metadata +146 -91
  64. data/VERSION.yml +0 -5
@@ -0,0 +1,14 @@
1
+ # bump..
2
+ class CoolWorker < IronWorker::Base
3
+ attr_accessor :array_of_models
4
+ merge '../models/cool_model'
5
+
6
+
7
+ def run
8
+ 10.times do |i|
9
+ puts "HEY THERE PUTS #{i}"
10
+ log "HEY THERE LOG #{i}"
11
+ sleep 1
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # bump..........
2
+ #
3
+ #require 'mysql2'
4
+ #
5
+ #class DbWorker < IronWorker::Base
6
+ # merge_gem 'activerecord', :require=>'active_record'
7
+ # merge '../models/db_model'
8
+ #
9
+ #
10
+ # def run
11
+ #
12
+ # n = DbModel.new(:name=>"jane", :age=>21)
13
+ # n.save!
14
+ #
15
+ # to = DbModel.first
16
+ # puts 'found: ' + to.inspect
17
+ # @object = to
18
+ #
19
+ # n.delete
20
+ # end
21
+ #
22
+ # def ob
23
+ # @object
24
+ # end
25
+ #
26
+ #
27
+ #end
@@ -0,0 +1,10 @@
1
+ # bump......
2
+ class FailWorker < IronWorker::Base
3
+
4
+ attr_accessor :x
5
+
6
+ def run
7
+ puts "I am about to fail..."
8
+ raise "I wanted to fail and I did!"
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # bump..
2
+ class GemDependencyWorker < IronWorker::Base
3
+
4
+ #merge_gem "signature"
5
+ merge_gem "pusher"
6
+
7
+ attr_accessor :some_param
8
+
9
+ def run
10
+ log "Starting HelloWorker #{Time.now}\n"
11
+ log "Hey. I'm a worker job, showing how this cloud-based worker thing works."
12
+ log "I'll sleep for a little bit so you can see the workers running!"
13
+ log "some_param --> #{some_param}\n"
14
+ sleep 10
15
+ log "Done running HelloWorker #{Time.now}"
16
+ end
17
+
18
+
19
+ end
20
+
@@ -0,0 +1,65 @@
1
+ # bump......
2
+ class HackerWorker < IronWorker::Base
3
+
4
+ #merge_gem 'stathat'
5
+
6
+ attr_accessor :x
7
+
8
+ def run
9
+ puts "hello world! #{x}"
10
+ #puts StatHat::API.class.name
11
+ puts "\n"
12
+
13
+ puts 'user_dir: ' + user_dir.to_s
14
+ puts "\n"
15
+ command 'pwd'
16
+
17
+ filepath = "#{user_dir}myfile.txt"
18
+ puts "Writing file to #{filepath}..."
19
+ File.open(filepath, 'w') do |fo|
20
+ fo.write "THIS IS MY FILE"
21
+ end
22
+
23
+ command 'node --version'
24
+ command 'go version', :includes=>'go version go1'
25
+ command 'java -version', :includes=>'icedtea'
26
+ command 'mono -V', :includes=>'Mono JIT compliler version'
27
+ command 'gmcs hello.cs'
28
+
29
+
30
+ command 'ls -al'
31
+ command 'cat myfile.txt'
32
+ command 'echo "hello" >> greetings.txt'
33
+ command 'cat myfile.txt'
34
+ command 'ls -al /usr/bin'
35
+ command 'ls -al /mnt'
36
+ command 'ps -ef'
37
+ command 'cat /etc/passwd'
38
+ command 'env'
39
+ puts 'RUBY ENV:'
40
+ puts ENV.inspect
41
+ puts "\n"
42
+ command 'gem environment'
43
+ command 'gem list', :includes=>'typhoeus'
44
+ begin
45
+ command 'sudo ps -ef'
46
+ raise "Should not make it here!"
47
+ rescue => ex
48
+ puts "Expected error running sudo: #{ex.class.name}: #{ex.message}"
49
+ end
50
+ command 'su root'
51
+ command 'ls -al /home/ubuntu'
52
+ command 'ls -al /root'
53
+
54
+ end
55
+
56
+ def command(s, params={})
57
+ puts "Running #{s}:"
58
+ res = `#{s}`
59
+ if params[:includes]
60
+ raise "Did not include #{params[:includes]}" unless res.include?(params[:includes])
61
+ end
62
+ puts res
63
+ puts "\n"
64
+ end
65
+ end
@@ -0,0 +1,22 @@
1
+ # Bump...............
2
+ class TestWorker < IronWorker::Base
3
+
4
+ attr_accessor :s3_key, :times
5
+
6
+ def initialize
7
+ @times = 1
8
+ end
9
+
10
+ def run
11
+ log 'running the test worker for moi '.upcase
12
+ log 's3_key instance_variable = ' + self.s3_key.to_s
13
+
14
+ @times.times do |i|
15
+ puts 'running at ' + i.to_s
16
+ sleep 1
17
+ set_progress(:percent => (1.0 * i / @times * 100).round, :msg => "getting there...")
18
+ end
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,53 @@
1
+ # Bump..................
2
+ require_relative "one_line_worker"
3
+ class TestWorker2 < IronWorker::Base
4
+
5
+ merge File.join(File.dirname(__FILE__), '../' 'models', 'model_1.rb')
6
+ unmerge '../models/model_2.rb'
7
+ merge_worker File.join(File.dirname(__FILE__), 'second_worker.rb'), ' SecondWorker'
8
+ merge_worker File.join(File.dirname(__FILE__), 'one_line_worker.rb'), OneLineWorker
9
+ #merge_worker 'second_worker.rb', 'SecondWorker'
10
+
11
+ attr_accessor :s3_key, :times, :x
12
+
13
+ def super_class_method
14
+ puts 'This is a super_class_method'
15
+ end
16
+
17
+
18
+ def who_am_i2?
19
+ return self.class.name
20
+ end
21
+
22
+ def run
23
+ log 'running the runner for leroy '.upcase + ' with data: '
24
+
25
+ log 's3_key instance_variable = ' + self.s3_key
26
+ times.times do |i|
27
+ log 'running at ' + i.to_s
28
+ sleep 0.3
29
+ #set_progress(:percent=> (i / times * 100))
30
+ end
31
+ m1 = Model1.new
32
+ log "I made a new model1"
33
+ m1.say_hello
34
+
35
+ second_workers = []
36
+ now = Time.now
37
+ #10.times do |i|
38
+ # second_worker = SecondWorker.new
39
+ # second_worker.start_time = now
40
+ # second_worker.num = i
41
+ # second_worker.queue
42
+ # second_workers << second_worker
43
+ #end
44
+ #
45
+ #10.times do |i|
46
+ # second_workers.each do |sw|
47
+ # puts sw.to_s
48
+ # puts sw.status["status"].to_s
49
+ # end
50
+ #end
51
+ end
52
+
53
+ end
@@ -0,0 +1,17 @@
1
+ #bump...........,...
2
+ require_relative 'iw_test_worker_2'
3
+
4
+ class TestWorker3 < TestWorker2
5
+
6
+
7
+ attr_accessor :x, :db_user, :db_pass
8
+
9
+ def run()
10
+ puts 'TestWorker3.run'
11
+ @x = 123
12
+ super_class_method
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,9 @@
1
+ class LocalVsRemoteWorker < IronWorker::Base
2
+
3
+ attr_accessor :x
4
+
5
+ def run
6
+ puts "is_local? #{is_local?}"
7
+ puts "is_remote? #{is_remote?}"
8
+ end
9
+ end
@@ -0,0 +1,40 @@
1
+ # bump.......................
2
+
3
+ class MergingWorker < IronWorker::Base
4
+
5
+ merge_gem 'mini_fb'
6
+ #merge_gem 'carrierwave', :require=>['carrierwave', 'carrierwave/orm/activerecord']
7
+ merge_folder '../models'
8
+
9
+ merge 'models/cool_model'
10
+ unmerge 'models/model_2.rb'
11
+ merge_worker 'second_worker.rb', 'SecondWorker'
12
+
13
+ attr_accessor :s3_key, :times, :x
14
+
15
+ def run
16
+ raise "Model2 was found!" if defined?(Model2)
17
+ m1 = Model1.new
18
+ log "I made a new model1"
19
+ m1.say_hello
20
+
21
+ second_workers = []
22
+ now = Time.now
23
+ 10.times do |i|
24
+ second_worker = SecondWorker.new
25
+ second_worker.start_time = now
26
+ second_worker.num = i
27
+ second_worker.queue
28
+ second_workers << second_worker
29
+ end
30
+
31
+ second_workers.each do |sw|
32
+ puts sw.to_s
33
+ puts sw.status["status"].to_s
34
+ p sw.wait_until_complete.inspect
35
+ end
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,21 @@
1
+ # bump......
2
+ class MqWorker < IronWorker::Base
3
+
4
+ merge_gem 'iron_mq'
5
+
6
+ attr_accessor :config
7
+
8
+ def run
9
+ rest = Rest::Client.new
10
+ resp = rest.get 'http://169.254.169.254/2009-04-04/meta-data/instance-id'
11
+ puts 'instance_id=' + resp.body
12
+ @mq = IronMQ::Client.new(:token=>config['token'], :project_id=>config['project_id'], :queue_name=>'mq_worker')
13
+ puts 'putting message on queue'
14
+ resp = @mq.messages.post("Hello world!")
15
+ puts "posted #{resp.id}"
16
+ puts 'getting message from queue'
17
+ resp = @mq.messages.get
18
+ puts 'got: ' + resp.body
19
+
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # bump......
2
+ class OneLineWorker < IronWorker::Base
3
+
4
+
5
+ attr_accessor :x
6
+
7
+ def run
8
+ puts "hello world! #{x}"
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # bump.............
2
+
3
+ class PrawnWorker < IronWorker::Base
4
+
5
+ merge '../resources/something.yml'
6
+ merge_gem 'prawn', :include_dirs=>['data']
7
+ merge_gem "pdf-reader"
8
+
9
+ attr_accessor :x
10
+
11
+ def run()
12
+ puts 'TestWorker4.run'
13
+
14
+ #something = YAML.load('resources/something.yml')
15
+ #p something
16
+
17
+ Prawn::Document.generate("hello.pdf") do
18
+ text "Hello World!"
19
+ end
20
+
21
+ # now list files to see that it was created
22
+ puts "files in user_dir"
23
+ Dir.glob("*").each do |f|
24
+ puts f
25
+ end
26
+
27
+
28
+
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,26 @@
1
+ # Bump...............
2
+ class ProgressWorker < IronWorker::Base
3
+
4
+ attr_accessor :s3_key, :times, :x
5
+
6
+ def initialize
7
+ @times = 10
8
+ end
9
+
10
+ def run
11
+ puts 'hello'
12
+ puts 'running the test worker for moi '.upcase
13
+ puts 's3_key instance_variable = ' + self.s3_key.to_s
14
+
15
+ @times.times do |i|
16
+ puts 'loop ' + i.to_s
17
+ sleep 1
18
+ progress = (1.0 * i / @times * 100).round
19
+ puts 'Setting progress to ' + progress.to_s
20
+ set_progress(:percent=> progress, :msg=>"getting there...")
21
+ end
22
+ end
23
+
24
+
25
+ end
26
+
@@ -0,0 +1,17 @@
1
+ class QbWorker < IronWorker::Base
2
+
3
+ merge_worker 'running_back_worker', 'RunningBackWorker'
4
+
5
+ attr_accessor :x
6
+
7
+ def run
8
+ #IronWorker.logger.level = Logger::DEBUG
9
+ puts "Qb passing off to running backs..."
10
+ x ||= 10
11
+ x.times do |i|
12
+ worker = RunningBackWorker.new
13
+ worker.i = i
14
+ worker.queue(:priority=>0)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # bump......
2
+ class RailsWorker < IronWorker::Base
3
+
4
+ merge_worker 'rails_worker2', 'RailsWorker2'
5
+
6
+ def run
7
+ puts "hello rails! env=#{Rails.env}"
8
+ worker2 = nil
9
+ 10.times do |i|
10
+ worker2 = RailsWorker2.new
11
+ worker2.x = "yz #{i}"
12
+ worker2.queue(:priority=>2)
13
+ end
14
+
15
+ worker2.wait_until_complete
16
+ sleep 2
17
+ log = worker2.get_log
18
+ puts "START WORKER2 LOG:"
19
+ puts log
20
+ puts "END WORKER2 LOG"
21
+
22
+
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+
2
+ # bump......
3
+ class RailsWorker2 < IronWorker::Base
4
+ attr_accessor :x
5
+
6
+ def run
7
+ puts "I am #2. hello rails! env=#{Rails.env}"
8
+ puts "x=#{x}"
9
+
10
+ end
11
+ end
12
+
@@ -0,0 +1,4 @@
1
+
2
+
3
+ require_relative 'models/model_1.rb'
4
+
@@ -0,0 +1,7 @@
1
+ class RunningBackWorker < IronWorker::Base
2
+
3
+ attr_accessor :i
4
+ def run
5
+ puts "Running back #{i}"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ begin
2
+ require File.join(File.dirname(__FILE__), '../lib/iron_worker')
3
+ rescue Exception
4
+ require 'iron_worker'
5
+ end
6
+
7
+
8
+ class ScheduledWorker < IronWorker::Base
9
+
10
+ def run
11
+ log "This is scheduled yes it is"
12
+ log data.inspect
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ # bump..
2
+ class SecondWorker < IronWorker::Base
3
+ attr_accessor :start_time, :num
4
+
5
+ merge_worker 'third_worker.rb', 'ThirdWorker'
6
+
7
+ # change
8
+
9
+ def run
10
+ log self.to_s
11
+ end
12
+
13
+ def to_s
14
+ "I am Second Worker #{num}. I was started at #{start_time}"
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ # bump.............
2
+ class ThirdWorker < IronWorker::Base
3
+ def run
4
+ puts 'hi there, i am number 3'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # bump......
2
+ class WebhookWorker < IronWorker::Base
3
+
4
+ def run
5
+ puts "hello webhook! payload: #{IronWorker.payload}"
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require 'zip'
2
+ require 'zlib'
3
+
4
+ dir = Dir.new("./")
5
+ started_at = Time.now
6
+ fname2 = "zipped.zip"
7
+ Zip::ZipFile.open(fname2, 'w') do |f|
8
+ dir.each do |fname|
9
+ puts "merging #{fname} into #{fname2}"
10
+ f.add(File.basename(fname), fname)
11
+ end
12
+ end
13
+ ended_at = Time.now
14
+ puts "zip duration=#{(ended_at.to_f - started_at.to_f)}"
15
+
16
+ # todo: need to tar these first.
17
+ started_at = Time.now
18
+ fname2 = "gzipped.gzip"
19
+ Zlib::GzipWriter.open(fname2) do |gz|
20
+ dir.each do |fname|
21
+ puts "merging #{fname} into #{fname2}"
22
+ gz.write(File.basename(fname), fname)
23
+ end
24
+ end
25
+ ended_at = Time.now
26
+ puts "gzip duration=#{(ended_at.to_f - started_at.to_f)}"