Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
195 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Push | ||
class FeedbackProcessor | ||
def self.process(feedback) | ||
if feedback.instance_of? Push::FeedbackGcm | ||
if feedback.follow_up == 'delete' | ||
# TODO: delete gcm device | ||
|
||
elsif feedback.follow_up == 'update' | ||
# TODO: update gcm device | ||
# device = feedback.update_to | ||
|
||
end | ||
elsif feedback.instance_of? Push::FeedbackC2dm | ||
if feedback.follow_up == 'delete' | ||
# TODO: delete c2dm device | ||
|
||
end | ||
elsif feedback.instance_of? Push::FeedbackApns | ||
if feedback.follow_up == 'delete' | ||
# TODO: delete apns device | ||
|
||
end | ||
else | ||
Push::Daemon.logger.info("[FeedbackProcessor] Unknown feedback type") | ||
end | ||
end | ||
end | ||
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Push | ||
module Daemon | ||
module Feedback | ||
class FeedbackFeeder | ||
include ::Push::Daemon::DatabaseReconnectable | ||
include ::Push::Daemon::InterruptibleSleep | ||
|
||
def initialize(poll) | ||
@poll = poll | ||
end | ||
|
||
def name | ||
"FeedbackFeeder" | ||
end | ||
|
||
def start | ||
Thread.new do | ||
loop do | ||
break if @stop | ||
enqueue_feedback | ||
interruptible_sleep @poll | ||
end | ||
end | ||
end | ||
|
||
def stop | ||
@stop = true | ||
interrupt_sleep | ||
end | ||
|
||
protected | ||
|
||
def enqueue_feedback | ||
begin | ||
with_database_reconnect_and_retry(name) do | ||
if Push::Daemon.feedback_queue.notifications_processed? | ||
Push::Feedback.ready_for_followup.find_each do |feedback| | ||
Push::Daemon.feedback_queue.push(feedback) | ||
end | ||
end | ||
end | ||
rescue StandardError => e | ||
Push::Daemon.logger.error(e) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
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,48 @@ | ||
module Push | ||
module Daemon | ||
module Feedback | ||
class FeedbackHandler | ||
attr_reader :name | ||
STOP = 0x666 | ||
|
||
def initialize(processor) | ||
@name = "FeedbackHandler" | ||
require processor | ||
end | ||
|
||
def start | ||
Thread.new do | ||
loop do | ||
break if @stop | ||
handle_next_feedback | ||
end | ||
end | ||
end | ||
|
||
def stop | ||
@stop = true | ||
Push::Daemon.feedback_queue.push(STOP) | ||
end | ||
|
||
protected | ||
|
||
def handle_next_feedback | ||
feedback = Push::Daemon.feedback_queue.pop | ||
|
||
if feedback == STOP | ||
return | ||
end | ||
|
||
begin | ||
Push::FeedbackProcessor.process(feedback) | ||
feedback.is_processed(@name) | ||
rescue StandardError => e | ||
Push::Daemon.logger.error(e) | ||
ensure | ||
Push::Daemon.feedback_queue.notification_processed | ||
end | ||
end | ||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
module Push | ||
class Feedback < ActiveRecord::Base | ||
include Push::Daemon::DatabaseReconnectable | ||
self.table_name = 'push_feedback' | ||
|
||
scope :ready_for_followup, where(:processed => false) | ||
|
||
validates :device, :presence => true | ||
validates :follow_up, :presence => true | ||
validates :failed_at, :presence => true | ||
|
||
def is_processed(name) | ||
with_database_reconnect_and_retry(name) do | ||
self.processed = true | ||
self.processed_at = Time.now | ||
self.save | ||
end | ||
end | ||
end | ||
end |