dmantilla-delayed_job_sqs 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,5 +1,18 @@
1
1
  h1. Delayed Job for Amazon Simple Queue
2
2
 
3
+ h2. Running Jobs on the queue
4
+ <code>
5
+ Delayed::Job.work_off(sqs_queue)
6
+ </code>
7
+ This will pull messages from the queue and delete the message after, if the execution was successful.
8
+ Otherwise the message will remain on the queue.
9
+
10
+ h2. Displaying the messages awaiting execution
11
+ @Delayed::Job.list(sqs_queue)@ will return an array of the class and method to be executed.
12
+
13
+ @Deyaled::Job.expanded_list(sqs_queue)@ returns another array with a detailed view of the possible result of the execution.
14
+ It's currently working for emails only. It gives a preview of each email being sent.
15
+
3
16
  h3. Versions
4
17
 
5
18
  * 0.1.0: Initial release, based on delayed_job version 1.7.0
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "delayed_job_sqs"
5
- s.version = "0.1.4"
5
+ s.version = "0.1.5"
6
6
  s.date = "2009-07-17"
7
7
  s.summary = "Asynchronous queue execution using Amazon SQS -- Most of the code was extracted from the delayed_job gem"
8
8
  s.email = "daniel@celect.org"
data/lib/delayed/job.rb CHANGED
@@ -28,6 +28,13 @@ module Delayed
28
28
  end
29
29
  end
30
30
 
31
+ def to_s
32
+ @to_s ||= begin
33
+ payload = payload_object
34
+ payload.respond_to?(:examine) ? payload.examine : name
35
+ end
36
+ end
37
+
31
38
  def run(max_run_time = MAX_RUN_TIME)
32
39
  begin
33
40
  runtime = Benchmark.realtime do
@@ -96,11 +103,24 @@ module Delayed
96
103
 
97
104
  break if exit_flag
98
105
 
99
- puts "Success: #{success}, Failures: #{failure}"
100
106
  sleep(60)
101
107
  end
102
108
  end
103
109
 
110
+ def self.job_list(sqs_queue)
111
+ jobs = []
112
+ while(message = sqs_queue.receive); jobs << Job.new(message); end
113
+ jobs
114
+ end
115
+
116
+ def self.list(sqs_queue)
117
+ job_list(sqs_queue).collect {|j| j.name}
118
+ end
119
+
120
+ def self.expanded_list(sqs_queue)
121
+ job_list(sqs_queue).collect {|j| j.to_s}
122
+ end
123
+
104
124
  private
105
125
 
106
126
  def deserialize(source)
@@ -4,7 +4,7 @@ module Delayed
4
4
  delayed_method = Delayed::PerformableMethod.new(self, method.to_sym, args)
5
5
 
6
6
  # If an actual queue was provided and the message size is less than 8K, it's appended to the queue
7
- if sqs_queue.is_a?(RightAws::SqsGen2::Queue) && delayed_method.to_yaml.size > 8192
7
+ if sqs_queue.is_a?(RightAws::SqsGen2::Queue) && delayed_method.to_yaml.size < 8192
8
8
  Delayed::Job.enqueue(sqs_queue, delayed_method)
9
9
  else
10
10
  # else the method is executed, no queueing
@@ -17,7 +17,15 @@ module Delayed
17
17
  when AR_STRING_FORMAT then "#{$1}##{method}"
18
18
  else "Unknown##{method}"
19
19
  end
20
- end
20
+ end
21
+
22
+ def display_class_name
23
+ case self.object
24
+ when CLASS_STRING_FORMAT then $1
25
+ when AR_STRING_FORMAT then $1
26
+ else "Unknown"
27
+ end
28
+ end
21
29
 
22
30
  def perform
23
31
  load(object).send(method, *args.map{|a| load(a)})
@@ -26,6 +34,19 @@ module Delayed
26
34
  true
27
35
  end
28
36
 
37
+ # Display a friendlier view of the method to be executed before the actual execution
38
+ def examine
39
+ obj = load(object)
40
+ # if the method starts with "deliver_" assumes it's an ActionMailer object
41
+ if method.to_s =~ /^deliver_(.*)/
42
+ create_method = "create_#{$1}"
43
+ tmail_obj = obj.send(create_method.intern, *args.map{|a| load(a)})
44
+ tmail_obj.to_s
45
+ else
46
+ display_name
47
+ end
48
+ end
49
+
29
50
  private
30
51
 
31
52
  def load(arg)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmantilla-delayed_job_sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mantilla