-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enqueues information about cloned repos for scheduled actions
- Rakefile: extend queue tasks to clone reporting queue - application/services/summarize_folder.rb: enqueing step includes clone report queue - infrastructure/messaging/queue.rb: AWS SQS service gateway
- Loading branch information
Showing
7 changed files
with
104 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# frozen_string_literal: false | ||
|
||
folders = %w[github database/orm gitrepo] | ||
folders = %w[github database/orm gitrepo messaging] | ||
folders.each do |folder| | ||
require_relative "#{folder}/init.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: false | ||
|
||
Dir.glob("#{File.dirname(__FILE__)}/*.rb").each do |file| | ||
require file | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module CodePraise | ||
module Messaging | ||
## Queue wrapper for AWS SQS | ||
# Requires: AWS credentials loaded in ENV or through config file | ||
class Queue | ||
GROUP_ID = 'codepraise_api' | ||
IDLE_TIMEOUT = 5 # seconds | ||
|
||
def initialize(queue_url) | ||
@queue_url = queue_url | ||
@queue = Aws::SQS::Queue.new(queue_url) | ||
end | ||
|
||
## Sends message to queue | ||
# Usage: | ||
# q = Messaging::Queue.new(app.config.REPORT_QUEUE_URL) | ||
# q.send({data: "hello"}.to_json) | ||
def send(message) | ||
unique = message.hash.to_s + Time.now.hash.to_s | ||
|
||
@queue.send_message( | ||
message_body: message, | ||
message_group_id: GROUP_ID, | ||
message_deduplication_id: unique | ||
) | ||
end | ||
|
||
## Polls queue, yielding each messge | ||
# Usage: | ||
# q = Messaging::Queue.new(app.config.REPORT_QUEUE_URL) | ||
# q.poll { |msg| print msg.body.to_s } | ||
def poll | ||
poller = Aws::SQS::QueuePoller.new(@queue_url) | ||
poller.poll(idle_timeout: IDLE_TIMEOUT) do |msg| | ||
yield msg.body if block_given? | ||
end | ||
end | ||
end | ||
end | ||
end |