Module: SalesforceBulkAPINotifier

Extended by:
Configuration
Defined in:
lib/salesforce-bulkapi-notifier.rb,
lib/salesforce_bulkapi_notifier/version.rb,
lib/salesforce_bulkapi_notifier/configuration.rb,
lib/salesforce_bulkapi_notifier/slack_service.rb,
lib/salesforce_bulkapi_notifier/salesforce_service.rb

Defined Under Namespace

Modules: Configuration Classes: SalesforceService, SlackService

Constant Summary collapse

STDOUT =
$stdout
STDERR =
$stderr
VERSION =
'0.0.2'

Constants included from Configuration

Configuration::VALID_CONFIG_KEYS

Class Method Summary collapse

Methods included from Configuration

configure, extended, reset, setup

Class Method Details

.executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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