fourkites-sqspoller 0.1.11 → 0.1.12.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWZlOWI3Y2UzNTg3MWJiYTkwNDU4MzlmYzVjNGRlNDFmYmE2ZTc3Mw==
4
+ MjI4OWU4OGRhYmU2ZWNlYTY5NTgxOTAzYWVjNGM5MTkzZWE4ODMwZA==
5
5
  data.tar.gz: !binary |-
6
- YTZmNDkyMmQ2NWYzNzAyMTdjYTY5MDQxYzlkNzMzZDcxNjk0NmE1OQ==
6
+ YTJlM2VhYWVmNDMxZWE0NzRjYjg4MDM1ZmRlZTdkM2RkMmRmMWUxZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzQwYzEzYjg3OTE5ZjBlZWJmODU2OTczZmM3ZjhmYTI3MzVlZDZmZDg5NWUw
10
- MDY4YzVmNDQ4OGQ0MzQ3NTY1ODJkMzI3MDM4NWNjODEyMTdmNGI0NmFjZmFh
11
- YTY3NWI2OWVlMTZkYjZiODI3YzcxNjYyNmQyYzFlNjliODdlODU=
9
+ NDE4ZjMyZGQ3MWVmMjdlZmFmNWI4N2Y1NjU2M2VlNDYzOGI5MjRlZTg0NzU2
10
+ MGYyZjFlZjI1NTYwMzRjZGNiMzBjYWVjYWQ0YWExZTUyZjNiYThiNDM1OTAy
11
+ MjA0Mzc2MWM0MDFkYmE3ZGUyODJlZjM5ODk1MmRiNmZmYjQ0NGM=
12
12
  data.tar.gz: !binary |-
13
- MTFmNGEzMGZjOTRhYmQ2Yzg3NmFjYzFlM2Q2ZGY1ZWZkMDUwZmJiYzQxOTZm
14
- ZGMyMjE1OWY4NTM0NmRiYTQ4MTBhMWNhYjNiYmRkYmU4Y2ZlYWJjNjNjOWU1
15
- NDNlYWZmZDNkMjhjN2U2NWFlOWYwZDg5YzI1NTBiMjk1NTg1OTM=
13
+ Zjc2YTcyNzZhYjIwMTcxYWQzMTZmODlhMzM4NGQyNWE1NDY2NmM4OGIwOWZl
14
+ M2I4MzhkMjIxZDYyM2FjZmZhZDBhMTk3MzNmNmZjNTlmNzVhNjVjMTFjZDFi
15
+ ZWI0YTJhZGVhMTc0NzVkZDU2MDJiZjRlNjllODJjMTgwNTI0NTM=
data/bin/sqspoller CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/opt/rubies/ruby-2.2.2/bin/ruby
2
-
3
2
  require 'sqspoller'
4
3
 
5
4
 
@@ -7,5 +6,6 @@ puts "SQSPoller arguments check"
7
6
  ARGV.each do |arg|
8
7
  puts "arg: #{arg}"
9
8
  end
10
-
11
- Sqspoller::SqsPoller.start_poller ARGV[0], ARGV[1], ARGV[2], ARGV[3], ARGV[4]
9
+ puts "Starting poller"
10
+ Sqspoller::SqsPoller.start_poller ARGV[0], ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5]
11
+ puts "poller done"
@@ -19,7 +19,7 @@ module Sqspoller
19
19
  @connection_pool = Concurrent::RubyThreadPoolExecutor.new(max_threads: @worker_thread_pool_size, min_threads: 1, max_queue: @max_allowed_queue_size)
20
20
  end
21
21
 
22
- def process(message, message_id)
22
+ def process(queue_controller, message, queue_name)
23
23
  @semaphore.synchronize {
24
24
  @pending_schedule_tasks +=1
25
25
  if @connection_pool.queue_length == @max_allowed_queue_size
@@ -29,23 +29,22 @@ module Sqspoller
29
29
  end
30
30
  }
31
31
  begin
32
- @logger.info "Scheduling worker task for message: #{message_id}"
32
+ @logger.info "Scheduling worker task for queue: #{queue_name}, message: #{message.message_id}"
33
33
 
34
34
  @connection_pool.post do
35
35
  begin
36
- @logger.info "Starting worker task for message: #{message_id}"
37
- @worker_task.process(message, message_id)
36
+ @logger.info "Starting worker task for queue: #{queue_name}, message: #{message.message_id}"
37
+ @worker_task.process(message.body, message.message_id)
38
38
  @pending_schedule_tasks -= 1
39
- @logger.info "Finished worker task for message: #{message_id}"
39
+ @logger.info "Finished worker task for queue: #{queue_name}, message: #{message.message_id}"
40
+ queue_controller.delete_message message.receipt_handle
40
41
  rescue Exception => e
41
42
  @pending_schedule_tasks -= 1
42
- @logger.info "Caught error #{e.message}"
43
- raise :skip_delete
43
+ @logger.info "Caught error for message: #{message}, error: #{e.message}, #{e.backtrace.join("\n")}"
44
44
  end
45
45
  end
46
46
  rescue Concurrent::RejectedExecutionError => e
47
- @logger.info "Caught Concurrent::RejectedExecutionError #{e.message}"
48
- raise :skip_delete
47
+ @logger.info "Caught Concurrent::RejectedExecutionError for #{e.message}"
49
48
  end
50
49
  end
51
50
  end
@@ -33,17 +33,26 @@ module Sqspoller
33
33
  @logger.info "Poller thread started for queue: #{queue_url}"
34
34
  poller = Aws::SQS::QueuePoller.new(queue_url)
35
35
 
36
- poller.poll do |received_message|
37
- begin
38
- @logger.info "Received message #{received_message.message_id}"
39
- @task_delegator.process received_message.body, received_message.message_id
40
- rescue Exception => e
41
- puts "Encountered error, will not delete message. #{received_message.message_id}"
42
- throw :skip_delete
43
- end
36
+ while true
37
+ msgs = @sqs.receive_message :queue_url => queue_url
38
+ msgs.messages.each { |received_message|
39
+ begin
40
+ @logger.info "Received message #{received_message.message_id}"
41
+ @task_delegator.process self, received_message, @queue_name
42
+ rescue Exception => e
43
+ @logger.info "Encountered error #{e.message} while submitting message from queue #{queue_url}"
44
+ end
45
+ }
44
46
  end
45
47
  end
46
48
  end
47
49
 
50
+ def delete_message(receipt_handle)
51
+ @sqs.delete_message(
52
+ queue_url: @queue_details.queue_url,
53
+ receipt_handle: receipt_handle
54
+ )
55
+ end
56
+
48
57
  end
49
58
  end
@@ -15,16 +15,24 @@ module Sqspoller
15
15
  end
16
16
 
17
17
  def process(message, message_id)
18
+ params = {}
19
+ parsed_message = JSON.parse(message)
20
+ parsed_message.keys.each do |key|
21
+ puts "Creating a new params hash"
22
+ params[key] = ( parsed_message[key].is_a?(Hash) ? parsed_message[key].to_json : parsed_message[key])
23
+ end
18
24
  if @http_method.downcase == "post"
19
- response = Net::HTTP.post_form(@uri, JSON.parse(message))
25
+ response = Net::HTTP.post_form(@uri, JSON.parse(params))
20
26
  elsif @http_method.downcase == "get"
21
27
  uri = URI(@http_url)
22
- uri.query = URI.encode_www_form(JSON.parse(message))
28
+ uri.query = URI.encode_www_form(JSON.parse(params))
23
29
  response = Net::HTTP.get_response(uri)
24
30
  else
25
31
  raise "Invalid http_method provided. #{http_method}"
26
32
  end
27
- @logger.info "Got HTTP response as #{response.code}, #{response.body}"
33
+ if response.code.to_s != '200'
34
+ raise "Service did not return 200 OK response. #{response.code}"
35
+ end
28
36
  end
29
37
  end
30
38
 
data/sqspoller.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'sqspoller/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fourkites-sqspoller"
8
- spec.version = '0.1.11'
8
+ spec.version = '0.1.12.10'
9
9
  spec.authors = ["anshul-fk"]
10
10
  spec.email = ["anshul@fourkites.com"]
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fourkites-sqspoller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - anshul-fk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,8 +84,6 @@ description: ''
84
84
  email:
85
85
  - anshul@fourkites.com
86
86
  executables:
87
- - console
88
- - setup
89
87
  - sqspoller
90
88
  extensions: []
91
89
  extra_rdoc_files: []
@@ -96,8 +94,6 @@ files:
96
94
  - LICENSE
97
95
  - README.md
98
96
  - Rakefile
99
- - bin/console
100
- - bin/setup
101
97
  - bin/sqspoller
102
98
  - lib/sqspoller.rb
103
99
  - lib/sqspoller/message_delegator.rb
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "sqspoller"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here