rock-queue 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
7
7
  require 'rock-queue/tasks'
8
8
 
9
9
  GEM = "rock-queue"
10
- GEM_VERSION = "0.1.3"
10
+ GEM_VERSION = "0.1.5"
11
11
  AUTHOR = "Grzegorz Kazulak"
12
12
  EMAIL = "gregorz.kazulak@gmail.com"
13
13
  HOMEPAGE = "http://github.com/grzegorzkazulak/rock-queue"
@@ -7,11 +7,14 @@ module RockQueue
7
7
  base.send(:include, InstanceMethods)
8
8
  end
9
9
 
10
- module ClassMethods
11
- def self.perform(id, method, *args)
10
+ module ClassMethods
11
+ def perform(*args)
12
+ args = args.first
13
+ id = args.shift
14
+ method = args.shift
12
15
  find(id).send(method, *args)
13
16
  end
14
- end
17
+ end
15
18
 
16
19
  module InstanceMethods
17
20
  def async(method, *args)
@@ -10,24 +10,26 @@ module RockQueue
10
10
 
11
11
  attr_reader :obj
12
12
 
13
+ # Contructor of Resque adapter
13
14
  def initialize(options)
14
15
  Resque.redis = "#{options[:server]}:#{options[:port]}"
15
16
  end
16
17
 
17
- def push(value, options)
18
+ # Push item from Resque queue
19
+ def push(value, args)
18
20
  if !defined?(value.queue)
19
21
  value.class_eval do
20
22
  @queue = :default
21
23
  end
22
24
  end
23
- Resque.enqueue value
25
+ Resque.enqueue value, args
24
26
  end
25
-
27
+
28
+ # Retrieve item from Resque queue
26
29
  def pop
27
30
  job = Resque.reserve :default
28
- if job
29
- job.payload_class
30
- end
31
+ [job.payload_class, job.args] if job
31
32
  end
33
+
32
34
  end
33
35
  end
@@ -7,7 +7,7 @@ module RockQueue
7
7
  end
8
8
 
9
9
  # Notify by email
10
- def update(message)
10
+ def update(error)
11
11
 
12
12
  begin
13
13
  require 'mail'
@@ -15,7 +15,7 @@ module RockQueue
15
15
  puts "You need `mail` gem to use the Email Notifier"
16
16
  end
17
17
 
18
- puts "Sending e-mail message: #{message}"
18
+ puts "Sending e-mail message: #{error.message}"
19
19
 
20
20
  Mail.defaults do
21
21
  smtp do
@@ -24,16 +24,15 @@ module RockQueue
24
24
  user $server_config[:username]
25
25
  pass $server_config[:password]
26
26
  end
27
-
28
-
29
27
  end
30
28
 
31
29
  Mail.deliver do
32
30
  from $server_config[:from]
33
31
  to $server_config[:to]
34
- subject 'Processing error'
35
- body message.to_s
32
+ subject "Processing error - '#{error.message}''"
33
+ body error.backtrace.join("\n")
36
34
  end
35
+
37
36
  end
38
37
 
39
38
  end
@@ -5,11 +5,13 @@ module RockQueue
5
5
 
6
6
  DEFAULT_FAIL_LIMIT = 3
7
7
 
8
- attr_reader :object, :fails
8
+ attr_reader :object, :args, :fails
9
9
 
10
- def initialize(object)
10
+ # Constructor of queue objects wrapper
11
+ def initialize(object, args)
11
12
  @object = object
12
- @fails = Array.new
13
+ @args = args
14
+ @fails = Array.new
13
15
  end
14
16
 
15
17
  # Add processing fail
@@ -1,31 +1 @@
1
- <html>
2
- <head>
3
- <title>Rock Queue - Web interface</title>
4
- <style>
5
- body {
6
- font-family: Helvetica, sans-serif;
7
- }
8
-
9
- h1{
10
- font-size: 24px;
11
- }
12
- h2 {
13
- font-size: 14px;
14
- }
15
- </style>
16
- </head>
17
- <body>
18
- <h1>RockQueue Web Interface</h1>
19
-
20
- <% @workers = ['192.168.0.1:4344', '192.168.0.1:3434', '192.168.0.1:2333'] %>
21
-
22
- <h2>Workers list</h2>
23
- <ul>
24
- <% for worker in @workers do %>
25
- <li>
26
- <%= worker %>
27
- </li>
28
- <% end %>
29
- </ul>
30
- </body>
31
- </html>
1
+ RockQueue Web Interface
@@ -22,7 +22,8 @@ module RockQueue
22
22
  if queue
23
23
  # code that actually performs the action
24
24
  begin
25
- queue.object.perform
25
+ args = queue.args.first
26
+ args.empty? ? queue.object.perform : queue.object.perform(args)
26
27
  rescue Object => e
27
28
  # Add failed processing and retry
28
29
  if queue.add_fail(e)
data/lib/rock-queue.rb CHANGED
@@ -48,8 +48,8 @@ module RockQueue
48
48
 
49
49
  # Pushes the value (in our case it should always be an object)
50
50
  # onto the queue using previously selected adapter
51
- def push(value, *options)
52
- @adapter.push(value, options)
51
+ def push(value, *args)
52
+ @adapter.push(value, args)
53
53
  end
54
54
 
55
55
 
@@ -59,9 +59,9 @@ module RockQueue
59
59
  # All calls to the queueing server are made through the previosuly selected adaper.
60
60
  def receive
61
61
  if block_given?
62
- obj = @adapter.pop
62
+ obj, args = @adapter.pop
63
63
  if obj
64
- yield QueueObject.new(obj)
64
+ yield QueueObject.new(obj, args)
65
65
  end
66
66
  else
67
67
  raise 'No block given'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Kazulak
@@ -9,7 +9,7 @@ autorequire: rock-queue
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 +01:00
12
+ date: 2009-12-11 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15