dispatch-rider 0.2.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30af4d35a460ffed8231e8baf51fce6e2cd03d31
4
- data.tar.gz: 72064d34039b26cff1d57f1e378c261f68e7a59d
3
+ metadata.gz: a4c535bd0967d924fdfb552b3f06598be0cf7127
4
+ data.tar.gz: c20eca26575742fb5b88df1e14e899d4b2b6746f
5
5
  SHA512:
6
- metadata.gz: bafae95fb175d28736ac1ca3615c84d3e446f4736e82ba75582b092877f205dc363e9d9f26b36d8ddcc5f07b7103f63307f91ab656e557c8ffa080ea7a9e60bc
7
- data.tar.gz: 6fefbc2b6f0b5f72dad10835a76c1ae810abb4f391368eb1c71f0816fc1074d4611fb519eb2451e2e5569590bf3ef460dcfdb088bcb7700b98812b1cc1087f9f
6
+ metadata.gz: 5305e09afe9828e026e06aad912eeb18731dd0b9f185f5e7ab34a1aa6286b3699fbded8b52d4755fe28af3a39a0597aa3f9c54f37709eb8e80edc7ab6a4241fe
7
+ data.tar.gz: 959551fe0db50e4a11c4a0c5f0ef5c317e0aee97b3664f28a64e03abe08a840e0a8a4d2bb5d5e4e23a29afa637285ba922f750e33d423dd8c849190aae5b46b9
data/README.md CHANGED
@@ -7,7 +7,10 @@ handling the messages.
7
7
 
8
8
  ### Build status
9
9
 
10
- [![Build Status](https://travis-ci.org/payrollhero/dispatch-rider.png)](https://travis-ci.org/payrollhero/dispatch-rider)
10
+ [![Build Status](https://travis-ci.org/payrollhero/dispatch-rider.png?branch=master)](https://travis-ci.org/payrollhero/dispatch-rider)
11
+ [![Code Climate](https://codeclimate.com/github/payrollhero/dispatch-rider.png)](https://codeclimate.com/github/payrollhero/dispatch-rider)
12
+ [![Dependency Status](https://gemnasium.com/payrollhero/dispatch-rider.png)](https://gemnasium.com/payrollhero/dispatch-rider)
13
+
11
14
 
12
15
  ## Installation
13
16
 
@@ -5,6 +5,9 @@ module DispatchRider
5
5
  class AwsSqs < Base
6
6
  require "dispatch-rider/queue_services/aws_sqs/message_body_extractor"
7
7
 
8
+ class AbortExecution < RuntimeError; end
9
+ class VisibilityTimeoutExceeded < RuntimeError; end
10
+
8
11
  def assign_storage(attrs)
9
12
  begin
10
13
  sqs = AWS::SQS.new(:logger => nil)
@@ -20,12 +23,24 @@ module DispatchRider
20
23
  end
21
24
  end
22
25
 
23
- def insert(item)
24
- queue.send_message(item)
26
+ def pop(&block)
27
+ begin
28
+ queue.receive_message do |raw_item|
29
+ obj = OpenStruct.new(:item => raw_item, :message => construct_message_from(raw_item))
30
+
31
+ visibility_timout_shield(obj.message) do
32
+ raise AbortExecution, "false received from handler" unless block.call(obj.message)
33
+ obj.message
34
+ end
35
+
36
+ end
37
+ rescue AbortExecution
38
+ # ignore, it was already handled, just need to break out if pop
39
+ end
25
40
  end
26
41
 
27
- def raw_head
28
- queue.receive_message
42
+ def insert(item)
43
+ queue.send_message(item)
29
44
  end
30
45
 
31
46
  def construct_message_from(item)
@@ -39,6 +54,24 @@ module DispatchRider
39
54
  def size
40
55
  queue.approximate_number_of_messages
41
56
  end
57
+
58
+ private
59
+
60
+ def visibility_timeout
61
+ queue.visibility_timeout
62
+ end
63
+
64
+ def visibility_timout_shield(message)
65
+ start_time = Time.now
66
+ timeout = visibility_timeout # capture it at start
67
+ begin
68
+ yield
69
+ ensure
70
+ duration = Time.now - start_time
71
+ raise VisibilityTimeoutExceeded, "message: #{message.subject}, #{message.body.inspect} took #{duration} seconds while the timeout was #{timeout}" if duration > timeout
72
+ end
73
+ end
74
+
42
75
  end
43
76
  end
44
77
  end
@@ -30,36 +30,45 @@ module DispatchRider
30
30
  end
31
31
 
32
32
  def process
33
+ register_quit_trap
34
+ register_term_trap
35
+ register_int_trap
36
+
37
+ demultiplexer.start
38
+ end
39
+
40
+ private
41
+
42
+ def register_quit_trap
33
43
  Signal.trap("QUIT") do
34
44
  # signal number: 3
35
45
  logger.info "Received SIGQUIT, stopping demultiplexer"
36
46
  demultiplexer.stop
37
47
  end
48
+ end
38
49
 
50
+ def register_term_trap
39
51
  Signal.trap("TERM") do
40
52
  # signal number: 15
41
53
  logger.info "Received SIGTERM, stopping demultiplexer"
42
54
  demultiplexer.stop
43
55
  end
56
+ end
44
57
 
45
- # user interruption
46
- already_interrupted = false
58
+ def register_int_trap
59
+ @already_interrupted = false
47
60
  Signal.trap("INT") do
48
- if already_interrupted
61
+ if @already_interrupted
49
62
  logger.info "Received SIGINT second time, aborting"
50
63
  exit(0)
51
64
  else
52
65
  logger.info "Received SIGINT first time, stopping demultiplexer"
53
66
  demultiplexer.stop
54
67
  end
55
- already_interrupted = true
68
+ @already_interrupted = true
56
69
  end
57
-
58
- demultiplexer.start
59
70
  end
60
71
 
61
- private
62
-
63
72
  def logger
64
73
  DispatchRider.config.logger
65
74
  end
@@ -1,4 +1,4 @@
1
1
  # This file specifies the current version of the gem.
2
2
  module DispatchRider
3
- VERSION = "0.2.7"
3
+ VERSION = "1.0.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatch-rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suman Mukherjee
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-12-10 00:00:00.000000000 Z
14
+ date: 2013-12-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport