Skip to content

Commit

Permalink
Merge pull request #2273 from sparc-request/kg-epic_interface_error_h…
Browse files Browse the repository at this point in the history
…andling

KG - Improved Epic Interface Push Error Handling
  • Loading branch information
Stuart-Johnson committed Apr 3, 2020
2 parents cbc97a1 + 2eb86ac commit 0fff35f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,16 @@ def push_to_epic(epic_interface, origin, identity_id=nil, withhold_calendar=fals
self.last_epic_push_status = 'started'
save(validate: false)

Rails.logger.info("Sending study message to Epic")
Rails.logger.info("Sending study message to Epic - Study #{self.id}")
withhold_calendar ? epic_interface.send_study_creation(self) : epic_interface.send_study(self)

self.last_epic_push_status = 'complete'
save(validate: false)

EpicQueueRecord.create(protocol_id: self.id, status: self.last_epic_push_status, origin: origin, identity_id: identity_id)
rescue Exception => e
Rails.logger.info("Push to Epic failed.")
Rails.logger.error("Push to Epic failed - Study #{self.id}")
Rails.logger.error([e.message, *e.backtrace].join($/))

self.last_epic_push_status = 'failed'
save(validate: false)
Expand Down
15 changes: 9 additions & 6 deletions lib/tasks/send_to_epic.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@

task send_to_epic: :environment do

epic_queues = EpicQueue.where(user_change: true, attempted_push: false)
epic_queues = EpicQueue.eager_load(:protocol).where(user_change: true, attempted_push: false)

epic_queues.each do |eq|
p = Protocol.find(eq.protocol_id)
p.push_to_epic(EPIC_INTERFACE, eq.user_change? ? 'protocol_update' : 'admin_push', eq.identity_id, true)
if p.last_epic_push_status == 'complete'
eq.update_attribute(:attempted_push, true)
eq.destroy
begin
eq.protocol.push_to_epic(EPIC_INTERFACE, eq.user_change? ? 'protocol_update' : 'admin_push', eq.identity_id, true)
if p.last_epic_push_status == 'complete'
eq.update_attribute(:attempted_push, true)
eq.destroy
end
end
rescue Exception => e
# Do nothing, already logged by Protocol#push_to_epic
end
end

0 comments on commit 0fff35f

Please sign in to comment.