Class: Services::MdsPullAccount

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
FileUtils
Defined in:
app/models/services/mds_pull_account.rb

Constant Summary collapse

DECAY_TIME =

20 minutes

1200
STATUS_NEW =

Define all the statuses allowed for this object

0
STATUS_PROVIDERS_IDENTIFIED =
1
STATUS_ASSESSMENTS_REQUESTED =
2
STATUS_FILES_IDENTIFIED =
3
STATUS_FILES_DOWNLOADED =
4
STATUS_SUBMITTED_TO_ABAQIS =
5
STATUS_FILE_SYSTEM_CLEAN =
6
STATUS_REMOTE_CLEAN =
7
PROCESSING_STATES =

Define the order of statuses for this object. The statuses can proceed ONLY in this order

[ STATUS_NEW,
STATUS_PROVIDERS_IDENTIFIED,
STATUS_ASSESSMENTS_REQUESTED,
STATUS_FILES_IDENTIFIED,
STATUS_FILES_DOWNLOADED,
STATUS_SUBMITTED_TO_ABAQIS,
STATUS_FILE_SYSTEM_CLEAN,
STATUS_REMOTE_CLEAN ]
STATE_MACHINE =

Define the task to perform for each of the valid status, so if the current status of the object is STATUS_FILES_IDENTIFIED, then the :download_files method should be invoked. If the method is sucessful (doesn’t raise an exception), the status of the object is automatically moved to the next valid status (from the list above).

{
  STATUS_NEW                   => :identify_providers, #=> :identify_files_to_pull,
  STATUS_PROVIDERS_IDENTIFIED  => :request_assessments_to_process,
  STATUS_ASSESSMENTS_REQUESTED => :identify_files_to_pull,
  STATUS_FILES_IDENTIFIED      => :download_files,
  STATUS_FILES_DOWNLOADED      => :submit_files_to_abaqis,
  STATUS_SUBMITTED_TO_ABAQIS   => :clean_up_file_system,
  STATUS_FILE_SYSTEM_CLEAN     => :clean_up_remote_server
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_service_within_time_frame(service_key, from, to) ⇒ Object



78
79
80
81
82
83
84
# File 'app/models/services/mds_pull_account.rb', line 78

def self.for_service_within_time_frame(service_key, from, to)
  svc = Service.where(key: service_key).first
   = ConfiguredAccount.for_service(svc.id).enabled.pluck(:id)

  self.where("configured_account_id IN (?) AND created_at >= ? AND created_at <= ?",
             , from, to)
end

Instance Method Details

#processObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/services/mds_pull_account.rb', line 56

def process
  logger.info "Processing configured account: #{.to_rrepr}"

  # Update the attempt count for the MDS Pull Account record. (how many times have we tried
  # to process this record?)
  update_attribute :attempt, attempt + 1

  PROCESSING_STATES.each do | p_status |
    perform_task p_status
  end

rescue Exception => ex
  logger.error "Error processing configured account: #{self.to_rrepr}: #{ex.message}\n#{ex.backtrace.join("\n")}"
  if attempt > 1 && (attempt % 3 == 0)
    ServicesMailer.burying_job(self).deliver
    raise Ayl::Beanstalk::RequiresJobBury 
  else
    ServicesMailer.delaying_job(self).deliver
    raise Ayl::Beanstalk::RequiresJobDecay.new(DECAY_TIME)
  end
end