module SalesforceBulkAPINotifier

Constants

STDERR
STDOUT
VERSION

Public Class Methods

execute() click to toggle source
# File lib/salesforce-bulkapi-notifier.rb, line 35
def execute
  setup

  logger.info('Starting Salesforce BulkAPI Notifier')
  logger.info("Version: #{SalesforceBulkAPINotifier::VERSION}")

  loop do
    jobs = salesforce.get_all_jobs
    logger.debug("All Job Count: #{jobs.size}")
    started_at = Time.now.utc.to_datetime - interval_seconds.second
    logger.debug("Screening by time: #{started_at}")
    target_jobs = salesforce.screening_by_time(jobs, started_at)
    logger.debug("Target Job Count: #{target_jobs.size}")

    target_jobs.each do |job|
      job_info = salesforce.get_job_info(job['id'])
      logger.debug("Job Infomation: #{job_info}")
      job_status = salesforce.annotate(job_info)
      logger.debug("Job Status: #{job_status}")
      next if job_status[:success]

      logger.info(job_status)
      logger.info(job_info)
      slack.notify(slack_channel_name, "Job created by #{job_status[:user_name]} using BulkAPI failed due to '#{job_status[:message]}'.\nPlease check #{salesforce.instance_url}/#{job_info['id']}")
    end
    sleep interval_seconds.second
  end
rescue => e
  logger.fatal(e)
end