minion 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,10 @@ Minion pulls the AMQP credentials out the environment via AMQP_URL.
9
9
 
10
10
  $ export AMQP_URL="amqp://johndoe:abc123@localhost/my_vhost"
11
11
 
12
+ Alternativly you can explicitly set it programmatically like this:
13
+
14
+ Minion.amqp_url = "amqp://johndoe:abc123@localhost/my_vhost"
15
+
12
16
  If no URL is supplied, Minion defaults to "amqp://guest:guest@localhost/" which
13
17
  is the default credentials for Rabbitmq running locally.
14
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.1.12
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
5
+ require 'minion'
6
+ require 'activeresource' ## for 1.second
7
+
8
+ include Minion
9
+
10
+ error do |exception,queue,message,headers|
11
+ puts "got an error processing queue #{queue}"
12
+ puts exception.message
13
+ puts exception.backtrace
14
+ end
15
+
16
+ logger do |msg|
17
+ puts "--> #{msg}"
18
+ end
19
+
20
+ every 1.second do
21
+ announce "message.1", :foo => :bar
22
+ end
23
+
24
+ listen "message.1" do |args|
25
+ puts self.class
26
+ foobar
27
+ log "I received message.1 (and so did all other minions listening in)"
28
+ log "args were #{args}"
29
+ Minion.stop
30
+ end
31
+
32
+ listen "message.2" do |args|
33
+ log "I will not receive message.2"
34
+ end
35
+
36
+ ## problem - this is ideal for large data transport (where as the other kind isnt)
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
4
  require 'rubygems'
4
5
  require 'minion'
5
6
 
6
7
  include Minion
7
8
 
8
- error do |e|
9
- puts "got an error!"
9
+ error do |exception,queue,message,headers|
10
+ puts "got an error processing queue #{queue}"
11
+ puts exception.message
12
+ puts exception.backtrace
10
13
  end
11
14
 
12
15
  logger do |msg|
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
5
+ require 'minion'
6
+ require 'activeresource' ## for 1.second
7
+
8
+ include Minion
9
+
10
+ error do |exception,queue,message,headers|
11
+ puts "got an error processing queue #{queue}"
12
+ puts exception.message
13
+ puts exception.backtrace
14
+ end
15
+
16
+ logger do |msg|
17
+ puts "--> #{msg}"
18
+ end
19
+
20
+ Minion.decree "app_id.down", :zone => 1, :stack => "bamboo"
21
+
22
+ obey "app_id.down", :zone => 1, :stack => "bamboo" do
23
+ # something
24
+ end
25
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
5
+ require 'minion'
6
+ require 'activeresource'
7
+
8
+ include Minion
9
+
10
+ logger do |msg|
11
+ # puts "--> #{msg}"
12
+ end
13
+
14
+ tick = 100
15
+ span = 1..10
16
+
17
+ tasks = span.map { |i| "task.#{i}" }
18
+ base_data = { :time => Time.now, :type => "thing", :size => 123, :format => "octet/stream", :event_id => "0000000000000000000000000000000000000000000000000000" }
19
+
20
+ counter = 0
21
+ tasks.each do |task|
22
+ obey task, :type => "thing" do |args|
23
+ counter+=1
24
+ if counter % tick == 0
25
+ print "."
26
+ $stdout.flush
27
+ end
28
+ end
29
+ end
30
+
31
+ delay 1.second do
32
+ puts "go!!"
33
+ Minion.decree "start", {}
34
+ end
35
+
36
+ obey "done" do |args|
37
+ puts ""
38
+ puts "All done"
39
+ Minion.stop
40
+ end
41
+
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
5
+ require 'minion'
6
+ require 'activeresource'
7
+
8
+ include Minion
9
+
10
+ logger do |msg|
11
+ # puts "--> #{msg}"
12
+ end
13
+
14
+ tick = 100
15
+ span = 1..10
16
+
17
+ tasks = span.map { |i| "task.#{i}" }
18
+ base_data = { :time => Time.now, :type => "thing", :size => 123, :format => "octet/stream", :event_id => "0000000000000000000000000000000000000000000000000000" }
19
+
20
+ counter = 0
21
+ tasks.each do |task|
22
+ obey task, :type => "thing" do |args|
23
+ counter+=1
24
+ if counter % tick == 0
25
+ print "."
26
+ $stdout.flush
27
+ end
28
+ end
29
+ end
30
+
31
+ #delay 1.second do
32
+ # puts "go!!"
33
+ # Minion.decree "start", {}
34
+ #end
35
+
36
+ obey "done" do |args|
37
+ puts ""
38
+ puts "All done"
39
+ Minion.stop
40
+ end
41
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rubygems'
5
+ require 'minion'
6
+
7
+ include Minion
8
+
9
+ logger do |msg|
10
+ # puts "--> #{msg}"
11
+ end
12
+
13
+ count = 20000
14
+ span = 1..10
15
+ tasks = span.map { |i| "task.#{i}" }
16
+ base_data = { :type => "thing", :size => 123, :format => "octet/stream", :event_id => "0000000000000000000000000000000000000000000000000000" }
17
+
18
+ obey "start" do
19
+ puts "starting!"
20
+ count.times do
21
+ task = tasks[rand(tasks.size)]
22
+ Minion.decree task, base_data
23
+ end
24
+ Minion.decree "done", {}
25
+ end
26
+
27
+ #Minion.announce task, base_data
28
+
@@ -1,10 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
4
  require 'rubygems'
4
5
  require 'minion'
5
6
 
6
7
  include Minion
7
8
 
9
+ error do |exception,queue,message,headers|
10
+ puts "got an error processing queue #{queue}"
11
+ puts exception.message
12
+ puts exception.backtrace
13
+ end
14
+
8
15
  job "add.bread" do |args|
9
16
  { "bread" => "sourdough" }
10
17
  end
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
4
  require 'rubygems'
4
5
  require 'minion'
5
6
 
6
7
  include Minion
7
8
 
8
- error do |e|
9
- puts "got an error!"
9
+ error do |exception,queue,message,headers|
10
+ puts "got an error processing queue #{queue}"
11
+ puts exception.message
12
+ puts exception.backtrace
10
13
  end
11
14
 
12
15
  logger do |msg|
@@ -7,6 +7,10 @@ require 'minion/handler'
7
7
  module Minion
8
8
  extend self
9
9
 
10
+ def url=(url)
11
+ @@config_url = url
12
+ end
13
+
10
14
  def enqueue(jobs, data = {})
11
15
  raise "cannot enqueue a nil job" if jobs.nil?
12
16
  raise "cannot enqueue an empty job" if jobs.empty?
@@ -94,12 +98,16 @@ module Minion
94
98
  end
95
99
  end
96
100
 
97
- private
98
-
99
101
  def amqp_url
100
- ENV["AMQP_URL"] || "amqp://guest:guest@localhost/"
102
+ @@amqp_url ||= ENV["AMQP_URL"] || "amqp://guest:guest@localhost/"
101
103
  end
102
104
 
105
+ def amqp_url=(url)
106
+ @@amqp_url = url
107
+ end
108
+
109
+ private
110
+
103
111
  def amqp_config
104
112
  uri = URI.parse(amqp_url)
105
113
  {
@@ -125,7 +133,7 @@ module Minion
125
133
 
126
134
  def next_job(args, response)
127
135
  queue = args.delete("next_job")
128
- enqueue(queue,args.merge(response)) unless queue.empty?
136
+ enqueue(queue,args.merge(response)) if queue and not queue.empty?
129
137
  end
130
138
 
131
139
  def error_handler
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orion Henry
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-21 00:00:00 -08:00
12
+ date: 2010-01-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,11 @@ summary: Super simple job queue over AMQP
89
89
  test_files:
90
90
  - spec/base.rb
91
91
  - spec/enqueue_spec.rb
92
+ - examples/listen.rb
92
93
  - examples/math.rb
94
+ - examples/obey.rb
95
+ - examples/pull.rb
96
+ - examples/pull2.rb
97
+ - examples/push.rb
93
98
  - examples/sandwich.rb
94
99
  - examples/when.rb