salesforce-bulkapi-notifier 0.0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da816824549342c72e65bf3e77dbf6ca9389b94475834656a249835db83edb3e
4
+ data.tar.gz: 0c9d478b604b0fbdf1165ebfc65c78dce4a95bd2d9013f773041959765871d6c
5
+ SHA512:
6
+ metadata.gz: 55673ec3954a63337dd9ac4513cd40f69ebf1173ce298b5c68761390d18d3d0115704ae9e78cbfbaf6aeb84955ab8025f04a04d03028a9b905707f0ef1ce6404
7
+ data.tar.gz: 712d8bb6bfee22d9eb131fd1e9b2998ceaa17973c94a7a84367a15def20112b015db8a1d5a9b391ca7424a0a9c36dfa9dbcc5f288f5cc7946e06a0c4bcb1ea62
data/.dockerignore ADDED
@@ -0,0 +1,4 @@
1
+ .git
2
+ vender
3
+ .idea
4
+ .env
data/.env.sample ADDED
@@ -0,0 +1,7 @@
1
+ SLACK_API_TOKEN=xxx-your-token-here
2
+ SLACK_CHANNEL_NAME='#general' # Supported multi channel by using `,`. e,g #general,@kou
3
+ SALESFORCE_HOST=example.com
4
+ SALESFORCE_USER_ID=your@example.com
5
+ SALESFORCE_PASSWORD=your-password
6
+ SALESFORCE_CLIENT_ID=your-client-id
7
+ SALESFORCE_CLIENT_SECRET=your-client-secret
data/.gitignore ADDED
@@ -0,0 +1,59 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
57
+
58
+ # rspec failure tracking
59
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at cs006061@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,46 @@
1
+ FROM ruby:2.7.0
2
+
3
+ # Ruby
4
+ #-----------------------------------------------
5
+ ENV BUNDLER_VERSION 2.0.2
6
+
7
+ RUN gem install bundler --version "$BUNDLER_VERSION" \
8
+ # Ignore warning: "Don't run Bundler as root."
9
+ # @see https://github.com/docker-library/rails/issues/10
10
+ && bundle config --global silence_root_warning 1 \
11
+ # Ignore insecure `git` protocol for gem
12
+ && bundle config --global git.allow_insecure true
13
+
14
+ # Timezone
15
+ #-----------------------------------------------
16
+ ENV TZ Asia/Tokyo
17
+
18
+ # Locale
19
+ #-----------------------------------------------
20
+ RUN echo "ja_JP.UTF-8 UTF-8" > /etc/locale.gen \
21
+ && apt-get update && apt-get install -y locales \
22
+ && locale-gen ja_JP.UTF-8 \
23
+ && update-locale LANG=ja_JP.UTF-8 \
24
+ && apt-get clean \
25
+ && rm -rf /var/lib/apt/lists/*
26
+ ENV LC_CTYPE=ja_JP.UTF-8
27
+
28
+ # App
29
+ #-----------------------------------------------
30
+ WORKDIR /app
31
+ ENV PATH $PATH:/app/vendor/bundle/bin
32
+ ENV DOCKER_LOGS true
33
+
34
+ COPY Gemfile Gemfile.lock /app/
35
+
36
+ # As we vendor dependencies, we don't need gems in bundler system path (/usr/local/bundle)
37
+ ENV BUNDLE_PATH__SYSTEM=false
38
+
39
+ RUN bundle install \
40
+ --path vendor/bundle \
41
+ --binstubs vendor/bundle/bin \
42
+ --without test development \
43
+ --jobs 8
44
+
45
+ COPY . /app
46
+ CMD ["bundle", "exec", "bin/runner"]
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in salesforce-bulkapi-notifier.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "guard"
8
+ gem "guard-rspec"
9
+ gem 'pry'
10
+ gem 'byebug'
11
+ gem 'pry-byebug'
12
+ gem 'rspec'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ salesforce-bulkapi-notifier (0.0.1.pre)
5
+ dotenv
6
+ faraday
7
+ faraday_middleware
8
+ httpclient
9
+ slack-ruby-client
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (6.0.2.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ zeitwerk (~> 2.2)
20
+ byebug (11.1.1)
21
+ coderay (1.1.2)
22
+ concurrent-ruby (1.1.5)
23
+ diff-lcs (1.3)
24
+ dotenv (2.7.5)
25
+ faraday (0.17.3)
26
+ multipart-post (>= 1.2, < 3)
27
+ faraday_middleware (0.14.0)
28
+ faraday (>= 0.7.4, < 1.0)
29
+ ffi (1.12.2)
30
+ formatador (0.2.5)
31
+ gli (2.19.0)
32
+ guard (2.16.1)
33
+ formatador (>= 0.2.4)
34
+ listen (>= 2.7, < 4.0)
35
+ lumberjack (>= 1.0.12, < 2.0)
36
+ nenv (~> 0.1)
37
+ notiffany (~> 0.0)
38
+ pry (>= 0.9.12)
39
+ shellany (~> 0.0)
40
+ thor (>= 0.18.1)
41
+ guard-compat (1.2.1)
42
+ guard-rspec (4.7.3)
43
+ guard (~> 2.1)
44
+ guard-compat (~> 1.1)
45
+ rspec (>= 2.99.0, < 4.0)
46
+ hashie (4.1.0)
47
+ httpclient (2.8.3)
48
+ i18n (1.8.2)
49
+ concurrent-ruby (~> 1.0)
50
+ listen (3.2.1)
51
+ rb-fsevent (~> 0.10, >= 0.10.3)
52
+ rb-inotify (~> 0.9, >= 0.9.10)
53
+ lumberjack (1.2.4)
54
+ method_source (0.9.2)
55
+ minitest (5.14.0)
56
+ multipart-post (2.1.1)
57
+ nenv (0.3.0)
58
+ notiffany (0.1.3)
59
+ nenv (~> 0.1)
60
+ shellany (~> 0.0)
61
+ pry (0.12.2)
62
+ coderay (~> 1.1.0)
63
+ method_source (~> 0.9.0)
64
+ pry-byebug (3.8.0)
65
+ byebug (~> 11.0)
66
+ pry (~> 0.10)
67
+ rake (10.5.0)
68
+ rb-fsevent (0.10.3)
69
+ rb-inotify (0.10.1)
70
+ ffi (~> 1.0)
71
+ rspec (3.9.0)
72
+ rspec-core (~> 3.9.0)
73
+ rspec-expectations (~> 3.9.0)
74
+ rspec-mocks (~> 3.9.0)
75
+ rspec-core (3.9.1)
76
+ rspec-support (~> 3.9.1)
77
+ rspec-expectations (3.9.0)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.9.0)
80
+ rspec-mocks (3.9.1)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.9.0)
83
+ rspec-support (3.9.2)
84
+ shellany (0.0.1)
85
+ slack-ruby-client (0.14.5)
86
+ activesupport
87
+ faraday (>= 0.9)
88
+ faraday_middleware
89
+ gli
90
+ hashie
91
+ websocket-driver
92
+ thor (1.0.1)
93
+ thread_safe (0.3.6)
94
+ tzinfo (1.2.6)
95
+ thread_safe (~> 0.1)
96
+ websocket-driver (0.7.1)
97
+ websocket-extensions (>= 0.1.0)
98
+ websocket-extensions (0.1.4)
99
+ zeitwerk (2.2.2)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ bundler (~> 2.1)
106
+ byebug
107
+ guard
108
+ guard-rspec
109
+ pry
110
+ pry-byebug
111
+ rake (~> 10.0)
112
+ rspec
113
+ salesforce-bulkapi-notifier!
114
+
115
+ BUNDLED WITH
116
+ 2.1.4
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Kodai Sakabe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 koudaiii
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # salesforce-bulkapi-notifier
2
+
3
+ [![Docker Repository on Quay](https://quay.io/repository/koudaiii/salesforce-bulkapi-notifier/status "Docker Repository on Quay")](https://quay.io/repository/koudaiii/salesforce-bulkapi-notifier)
4
+ [![GitHub release](https://img.shields.io/github/release/koudaiii/salesforce-bulkapi-notifier.svg)](https://github.com/koudaiii/salesforce-bulkapi-notifier/releases)
5
+
6
+ ## Description
7
+ salesforce-bulkapi-notifier notify to slack when failed jobs. e.g. When job state is Failed or Error is higher than Error rate.
8
+
9
+ ## Table of Contents
10
+
11
+ - [salesforce-bulkapi-notifier](#salesforce-bulkapi-notifier)
12
+ - [Description](#description)
13
+ - [Table of Contents](#table-of-contents)
14
+ - [Requirements](#requirements)
15
+ - [Installation](#installation)
16
+ - [Run in a Docker container](#run-in-a-docker-container)
17
+ - [Usage](#usage)
18
+ - [Options](#options)
19
+ - [Development](#development)
20
+ - [Contribution](#contribution)
21
+ - [Author](#author)
22
+ - [License](#license)
23
+ - [Code of Conduct](#code-of-conduct)
24
+
25
+ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc.go)
26
+
27
+ ## Requirements
28
+
29
+ - Ruby 2.7 or later
30
+ - Set env
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'salesforce-bulkapi-notifier'
38
+ ```
39
+ And then execute:
40
+
41
+ ```console
42
+ $ bundle
43
+ ```
44
+
45
+ Or install it yourself as:
46
+
47
+ ```console
48
+ $ gem install salesforce-bulkapi-notifier
49
+ ```
50
+
51
+ ### Run in a Docker container
52
+
53
+ TBD
54
+
55
+ ## Usage
56
+
57
+ TBD
58
+
59
+ ## Options
60
+
61
+ TBD
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contribution
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/koudaiii/salesforce-bulkapi-notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
+
73
+ 1. Fork ([https://github.com/koudaiii/salesforce-bulkapi-notifier/fork](https://github.com/koudaiii/salesforce-bulkapi-notifier/fork))
74
+ 1. Create a feature branch
75
+ 1. Commit your changes
76
+ 1. Rebase your local changes against the master branch
77
+ 1. Run test suite with the `bundle exec rspec` command and confirm that it passes
78
+ 1. Create a new Pull Request
79
+
80
+ ## Author
81
+
82
+ [koudaiii](https://github.com/koudaiii)
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the Salesforce-bulkapi-notifier project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/koudaiii/salesforce-bulkapi-notifier/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "salesforce_bulkapi_notifier"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/runner ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/salesforce_bulkapi_notifier'
4
+
5
+ SalesforceBulkAPINotifier.configure do |c|
6
+ c.slack_api_token = ENV['SLACK_API_TOKEN']
7
+ c.slack_channel_name = ENV['SLACK_CHANNEL_NAME']
8
+ c.salesforce_host = ENV['SALESFORCE_HOST']
9
+ c.salesforce_user_id = ENV['SALESFORCE_USER_ID']
10
+ c.salesforce_password = ENV['SALESFORCE_PASSWORD']
11
+ c.salesforce_client_id = ENV['SALESFORCE_CLIENT_ID']
12
+ c.salesforce_client_secret = ENV['SALESFORCE_CLIENT_SECRET']
13
+ c.error_rate = ENV['ERROR_RATE'].to_i || 10
14
+ c.interval_seconds = ENV['INTERVAL_SECONDS'].to_i || 60
15
+ c.logger.level = :debug
16
+ end
17
+
18
+ exit SalesforceBulkAPINotifier.execute
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,67 @@
1
+ require_relative 'salesforce_bulkapi_notifier/version'
2
+ require_relative 'salesforce_bulkapi_notifier/configuration'
3
+ require_relative 'salesforce_bulkapi_notifier/salesforce_service'
4
+ require_relative 'salesforce_bulkapi_notifier/slack_service'
5
+
6
+ require 'logger'
7
+ require 'slack-ruby-client'
8
+ require 'faraday'
9
+ require 'faraday_middleware'
10
+ require 'httpclient'
11
+ require 'dotenv'
12
+
13
+ module SalesforceBulkAPINotifier
14
+ extend Configuration
15
+ class << self
16
+ if ENV['DOCKER_LOGS']
17
+ $stdout = IO.new(IO.sysopen("/proc/1/fd/1", "w"),"w")
18
+ $stdout.sync = true
19
+ STDOUT = $stdout
20
+
21
+ $stderr = IO.new(IO.sysopen("/proc/1/fd/1", "w"),"w")
22
+ $stderr.sync = true
23
+ STDERR = $stderr
24
+ end
25
+
26
+ Signal.trap(:INT) do
27
+ puts 'Stopping Salesforce BulkAPI Notifier'
28
+ exit 0
29
+ end
30
+
31
+ Signal.trap('TERM') do
32
+ puts 'Stopping Salesforce BulkAPI Notifier'
33
+ exit 0
34
+ end
35
+
36
+ def execute
37
+ setup
38
+
39
+ logger.info('Starting Salesforce BulkAPI Notifier')
40
+ logger.info("Version: #{SalesforceBulkAPINotifier::VERSION}")
41
+
42
+ loop do
43
+ jobs = salesforce.get_all_jobs
44
+ logger.debug("All Job Count: #{jobs.size}")
45
+ started_at = Time.now.utc.to_datetime - interval_seconds.second
46
+ logger.debug("Screening by time: #{started_at}")
47
+ target_jobs = salesforce.screening_by_time(jobs, started_at)
48
+ logger.debug("Target Job Count: #{target_jobs.size}")
49
+
50
+ target_jobs.each do |job|
51
+ job_info = salesforce.get_job_info(job['id'])
52
+ logger.debug("Job Infomation: #{job_info}")
53
+ job_status = salesforce.annotate(job_info)
54
+ logger.debug("Job Status: #{job_status}")
55
+ next if job_status[:success]
56
+
57
+ logger.info(job_status)
58
+ logger.info(job_info)
59
+ 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']}")
60
+ end
61
+ sleep interval_seconds.second
62
+ end
63
+ rescue => e
64
+ logger.fatal(e)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,51 @@
1
+ module SalesforceBulkAPINotifier
2
+ module Configuration
3
+
4
+ VALID_CONFIG_KEYS = {
5
+ slack_api_token: '',
6
+ slack_channel_name: '',
7
+ salesforce_host: '',
8
+ salesforce_user_id: '',
9
+ salesforce_password: '',
10
+ salesforce_client_id: '',
11
+ salesforce_client_secret: '',
12
+ error_rate: 10,
13
+ interval_seconds: 60,
14
+ logger: nil,
15
+ salesforce: nil,
16
+ slack: nil,
17
+ }.freeze
18
+ attr_accessor(* VALID_CONFIG_KEYS.keys)
19
+
20
+ def configure
21
+ yield self
22
+ end
23
+
24
+ def self.extended(base)
25
+ Dotenv.load
26
+
27
+ raise 'Missing ENV[SLACK_API_TOKEN]!' unless ENV['SLACK_API_TOKEN']
28
+ raise 'Missing ENV[SLACK_CHANNEL_NAME]!' unless ENV['SLACK_CHANNEL_NAME']
29
+ raise 'Missing ENV[SALESFORCE_HOST]!' unless ENV['SALESFORCE_HOST']
30
+ raise 'Missing ENV[SALESFORCE_USER_ID]!' unless ENV['SALESFORCE_USER_ID']
31
+ raise 'Missing ENV[SALESFORCE_PASSWORD]!' unless ENV['SALESFORCE_PASSWORD']
32
+ raise 'Missing ENV[SALESFORCE_CLIENT_ID]!' unless ENV['SALESFORCE_CLIENT_ID']
33
+ raise 'Missing ENV[SALESFORCE_CLIENT_SECRET]!' unless ENV['SALESFORCE_CLIENT_SECRET']
34
+
35
+ base.reset
36
+ end
37
+
38
+ def reset
39
+ VALID_CONFIG_KEYS.each do |k, v|
40
+ send((k.to_s + '='), v)
41
+ end
42
+
43
+ self.logger = ::Logger.new(STDOUT)
44
+ end
45
+
46
+ def setup
47
+ self.salesforce = SalesforceService.new
48
+ self.slack = SlackService.new
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,94 @@
1
+ module SalesforceBulkAPINotifier
2
+ class SalesforceService
3
+ API_VERSION = 47.0
4
+ attr_reader :instance_url
5
+
6
+ def initialize
7
+ con = Faraday.new(url: "https://#{SalesforceBulkAPINotifier.salesforce_host}") do |c|
8
+ c.adapter :httpclient
9
+ c.request :json
10
+ end
11
+
12
+ # https://help.salesforce.com/articleView?id=remoteaccess_oauth_username_password_flow.htm&language=ja&type=0
13
+ response = con.post("/services/oauth2/token", {
14
+ grant_type: :password,
15
+ username: SalesforceBulkAPINotifier.salesforce_user_id,
16
+ password: SalesforceBulkAPINotifier.salesforce_password,
17
+ client_id: SalesforceBulkAPINotifier.salesforce_client_id,
18
+ client_secret: SalesforceBulkAPINotifier.salesforce_client_secret,
19
+ format: :json,
20
+ })
21
+
22
+ data = JSON.parse(response.body)
23
+
24
+ @access_token = data['access_token']
25
+ @instance_url = data['instance_url']
26
+ end
27
+
28
+ def rest_api_client
29
+ return nil unless @instance_url && @access_token
30
+ @rest_api_client ||=
31
+ Faraday.new(url: @instance_url) do |c|
32
+ c.adapter :httpclient
33
+ c.request :json
34
+ c.headers['Authorization'] = "OAuth #{@access_token}"
35
+ c.headers['Content-Type'] = 'application/json'
36
+ c.headers['charset'] = 'UTF-8'
37
+ end
38
+ end
39
+
40
+ # ref. https://developer.salesforce.com/docs/atlas.ja-jp.api_bulk_v2.meta/api_bulk_v2/get_all_jobs.htm
41
+ def get_all_jobs
42
+ res = rest_api_client.get("/services/data/v#{API_VERSION}/jobs/ingest")
43
+ raise res if res.status != 200
44
+ data = JSON.parse(res.body)
45
+ jobs = data['records']
46
+ done = data['done']
47
+
48
+ until done
49
+ res = rest_api_client.get(data['nextRecordsUrl'])
50
+ raise res if res.status != 200
51
+ data = JSON.parse(res.body)
52
+ done = data['done']
53
+ jobs += data['records']
54
+ end
55
+ jobs
56
+ end
57
+
58
+ # ref. https://developer.salesforce.com/docs/atlas.ja-jp.api_bulk_v2.meta/api_bulk_v2/get_job_info.htm
59
+ def get_job_info(sf_job_id)
60
+ res = rest_api_client.get("/services/data/v#{API_VERSION}/jobs/ingest/#{sf_job_id}")
61
+ raise res if res.status != 200
62
+ JSON.parse(res.body)
63
+ end
64
+
65
+ # ref. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_user_password.htm
66
+ def get_user_name(user_id)
67
+ res = rest_api_client.get("/services/data/v#{API_VERSION}/sobjects/User/#{user_id}")
68
+ raise res if res.status != 200
69
+ JSON.parse(res.body)['Name']
70
+ end
71
+
72
+ def screening_by_time(jobs, started_at)
73
+ jobs.map do |job|
74
+ job if job['systemModstamp'].to_datetime >= started_at
75
+ end.compact
76
+ end
77
+
78
+ def annotate(job_info)
79
+ user_name = get_user_name(job_info['createdById'])
80
+ error_rate = ((job_info['numberRecordsFailed'].to_f / job_info['numberRecordsProcessed'].to_f) * 100).floor(2)
81
+
82
+ job_status = {success: true, message: "Success", error_rate: error_rate, user_name: user_name}
83
+ if job_info['state'] == 'Failed'
84
+ job_status[:success] = false
85
+ job_status[:message] = "Job state is Failed"
86
+ elsif error_rate >= SalesforceBulkAPINotifier.error_rate && job_info['state'] == "Closed"
87
+ job_status[:success] = false
88
+ job_status[:message] = "Error rate is #{error_rate}%. Error percentage is higher than #{SalesforceBulkAPINotifier.error_rate}%"
89
+ else
90
+ end
91
+ job_status
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,17 @@
1
+ module SalesforceBulkAPINotifier
2
+ class SlackService
3
+ def initialize
4
+ Slack.configure do |config|
5
+ config.token = SalesforceBulkAPINotifier.slack_api_token
6
+ end
7
+ @slack ||= Slack::Web::Client.new
8
+ @slack.auth_test
9
+ end
10
+
11
+ def notify(channels, text)
12
+ channels.split(',').each do |channel|
13
+ @slack.chat_postMessage(channel: "#{channel}", text: "#{text}", as_user: true)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module SalesforceBulkAPINotifier
2
+ VERSION = '0.0.1.pre'
3
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "salesforce_bulkapi_notifier/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "salesforce-bulkapi-notifier"
8
+ spec.version = SalesforceBulkAPINotifier::VERSION
9
+ spec.authors = ["koudaiii"]
10
+ spec.email = ["cs006061@gmail.com"]
11
+
12
+ spec.summary = %q{salesforce-bulkapi-notifier notify to slack}
13
+ spec.description = %q{salesforce-bulkapi-notifier notify to slack when failed jobs. e.g. When job state is Failed or Error is higher than Error rate.}
14
+ spec.homepage = "https://github.com/koudaiii/salesforce-bulkapi-notifier"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency 'faraday'
27
+ spec.add_dependency 'faraday_middleware'
28
+ spec.add_dependency 'httpclient'
29
+ spec.add_dependency 'slack-ruby-client'
30
+ spec.add_dependency 'dotenv'
31
+
32
+ spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "byebug"
34
+ spec.add_development_dependency "pry-byebug"
35
+ spec.add_development_dependency "bundler", "~> 2.1"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salesforce-bulkapi-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - koudaiii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-ruby-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '10.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '10.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ description: salesforce-bulkapi-notifier notify to slack when failed jobs. e.g. When
168
+ job state is Failed or Error is higher than Error rate.
169
+ email:
170
+ - cs006061@gmail.com
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".dockerignore"
176
+ - ".env.sample"
177
+ - ".gitignore"
178
+ - ".rspec"
179
+ - ".travis.yml"
180
+ - CODE_OF_CONDUCT.md
181
+ - Dockerfile
182
+ - Gemfile
183
+ - Gemfile.lock
184
+ - Guardfile
185
+ - LICENSE
186
+ - LICENSE.txt
187
+ - README.md
188
+ - Rakefile
189
+ - bin/console
190
+ - bin/runner
191
+ - bin/setup
192
+ - lib/salesforce_bulkapi_notifier.rb
193
+ - lib/salesforce_bulkapi_notifier/configuration.rb
194
+ - lib/salesforce_bulkapi_notifier/salesforce_service.rb
195
+ - lib/salesforce_bulkapi_notifier/slack_service.rb
196
+ - lib/salesforce_bulkapi_notifier/version.rb
197
+ - salesforce-bulkapi-notifier.gemspec
198
+ homepage: https://github.com/koudaiii/salesforce-bulkapi-notifier
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">"
214
+ - !ruby/object:Gem::Version
215
+ version: 1.3.1
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.7.6
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: salesforce-bulkapi-notifier notify to slack
222
+ test_files: []