-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnsentDocumentsService ignores missing and closed tickets
- service determines ZD instance for ticket based on intake Co-authored-by: Ben Golder <bgolder@codeforamerica.org>
- Loading branch information
Showing
2 changed files
with
87 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
class UnsentDocumentsService | ||
include ZendeskServiceHelper | ||
include Rails.application.routes.url_helpers | ||
|
||
def instance | ||
@instance ||= EitcZendeskInstance | ||
end | ||
|
||
def detect_unsent_docs_and_notify | ||
DatadogApi.increment("cronjob.documents.unsent.detect_and_notify") | ||
|
||
tickets_updated = 0 | ||
Intake.where.not(intake_ticket_id: nil).find_each(batch_size: 100) do |intake| | ||
unsent_docs = intake.documents.where(zendesk_ticket_id: nil).where("created_at < ?", 15.minutes.ago) | ||
if unsent_docs.present? | ||
comment_body = <<~BODY | ||
New client documents are available to view: #{zendesk_ticket_url(id: intake.intake_ticket_id)} | ||
Files uploaded: | ||
#{unsent_docs.map {|d| "* #{d.upload.filename} (#{d.document_type})"}.join("\n")} | ||
BODY | ||
zendesk_service = ZendeskIntakeService.new(intake) | ||
|
||
append_comment_to_ticket( | ||
ticket_id: intake.intake_ticket_id, | ||
comment: comment_body | ||
) | ||
unsent_docs.each {|d| d.update(zendesk_ticket_id: intake.intake_ticket_id)} | ||
tickets_updated += 1 | ||
DatadogApi.gauge("zendesk.ticket.docs.unsent.ticket_updated.document_count", unsent_docs.length) | ||
ticket = zendesk_service.get_ticket(ticket_id: intake.intake_ticket_id) | ||
|
||
if ticket.present? && ticket.status != "closed" | ||
comment_body = <<~BODY | ||
New client documents are available to view: #{zendesk_ticket_url(id: intake.intake_ticket_id)} | ||
Files uploaded: | ||
#{unsent_docs.map {|d| "* #{d.upload.filename} (#{d.document_type})"}.join("\n")} | ||
BODY | ||
|
||
zendesk_service.append_comment_to_ticket( | ||
ticket_id: intake.intake_ticket_id, | ||
comment: comment_body | ||
) | ||
unsent_docs.each {|d| d.update(zendesk_ticket_id: intake.intake_ticket_id)} | ||
tickets_updated += 1 | ||
DatadogApi.gauge("zendesk.ticket.docs.unsent.ticket_updated.document_count", unsent_docs.length) | ||
end | ||
end | ||
end | ||
DatadogApi.gauge("zendesk.ticket.docs.unsent.tickets_updated", tickets_updated) | ||
DatadogApi.increment("cronjob.documents.unsent.detect_and_notify") | ||
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