Skip to content

Commit

Permalink
working on codeforamerica#203, notify endpoint publisher when failed …
Browse files Browse the repository at this point in the history
…sidekiq worker.
  • Loading branch information
masonpackard committed Sep 9, 2015
1 parent 7e592dc commit 5045a26
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/workers/publisher_poll.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'app/services/connection_builder'
require 'app/services/publisher_update'
require 'pony'

module Citygram::Workers
class PublisherPoll
Expand Down Expand Up @@ -34,6 +35,12 @@ def perform(publisher_id, url, page_number = 1)
end
end

sidekiq_retries_exhausted do |msg|
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
# send message to the publisher owner / contact
notify_publisher_contact(publisher)
end

private

def valid_next_page?(next_page, current_page)
Expand All @@ -44,5 +51,32 @@ def valid_next_page?(next_page, current_page)

next_page.host == current_page.host
end

def notify_publisher_contact(publisher_info)
Pony.options = {
from: ENV.fetch('SMTP_FROM_ADDRESS'),
via: :smtp,
via_options: {
enable_starttls_auto: true,
authentication: :plain,
address: ENV.fetch('SMTP_ADDRESS'),
port: ENV.fetch('SMTP_PORT'),
user_name: ENV.fetch('SMTP_USER_NAME'),
password: ENV.fetch('SMTP_PASSWORD'),
domain: ENV.fetch('SMTP_DOMAIN'),
}
}

body = "Notification Error.<hr>
Citygram has unsuccessfully tried to connect to your endpoint. <br>
Description: #{publisher_info.description}. <br>
Endpoint: #{publisher_info.endpoint}."

Pony.mail(
to: publisher_info.email, # TODO: need to add an email contact to the publisher endpoint.
subject: "Citygram publisher - endpoint error notification",
html_body: body,
)
end
end
end

3 comments on commit 5045a26

@bigfleet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attempt is 🔥 🔥 🔥

Unfortunately, though, we need something to back off sending it every ten minutes. 🚒 We would have sent the historic district one tens of thousands of times. Do you see a way to do (say) once a day?

@bigfleet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And tests wouldn't hurt! I do want to depend on this.

@masonpackard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly, a work in progress and test would certainly be appropriate. 😄

Figuring that once sidekiq retries is dead and can no longer attempt, then at that point the publisher endpoint contact would be emailed. At least this was my understanding according to sidekiq documentation, https://github.com/mperham/sidekiq/wiki/Error-Handling. There is the question of where or who is responsible for maintaining the publisher endpoint contact (ie. email).

  • in the publisher endpoint json
  • with in the citygram app it self

@bigfleet, what are your thoughts on this and introducing an error / log monitoring service or even help desk / 3rd party monitoring / paging integration? I am figuring that we may want to be cost conscientious.

Please sign in to comment.