- USERNAME: User name of user who have access to read accounts and contacts records
- PASSWORD: Password of the user
- SECURITY_TOKEN: Security token of the user. Check doc for details.
- CLIENT_ID: create a connected app Consumer Key
- CLIENT_SECRET: create a connected app Consumer Secret
- ACCOUNT_PUSH_TOPIC_NAME: Topic name for subscribing accounts for realtime changes. max_char: 25
- CONTACT_PUSH_TOPIC_NAME: Topic name for subscribing contacts for realtime changes. max_char: 25
- REDIS_URL: redis server url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If got following error while migrating rails app, which uses mysql-5.7, | |
``` | |
rake aborted! | |
LoadError: cannot load such file -- arel/visitors/mysql | |
/home/santosh/Documents/Danfhe/kirus/config/application.rb:7:in `<top (required)>' | |
/home/santosh/Documents/Danfhe/kirus/Rakefile:4:in `require_relative' | |
/home/santosh/Documents/Danfhe/kirus/Rakefile:4:in `<top (required)>' | |
(See full trace by running task with --trace) | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.9" | |
services: | |
db: | |
image: mysql:5.7 | |
restart: always | |
command: mysqld --sql_mode="" --character-set-server=utf8 --collation-server=utf8_general_ci | |
environment: | |
MYSQL_DATABASE: 'kirus_development' | |
MYSQL_ROOT_PASSWORD: 'password' | |
MYSQL_PASSWORD: 'password' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :streaming do | |
desc 'Fetch updates of Accounts data from salesforce push stream and update in database' | |
task accounts_and_contacts: :environment do | |
subscriber = SalesforceSubscriber.new | |
subscriber.create_account_push_topic | |
subscriber.create_contact_push_topic | |
subscriber.subscribe | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def subscribe | |
EM.run do | |
# Subscribe to the account PushTopic. | |
account_topic = ENV['ACCOUNT_PUSH_TOPIC_NAME'] | |
contact_topic = ENV['CONTACT_PUSH_TOPIC_NAME'] | |
@client.subscription "/topic/#{account_topic}" do |message| | |
Logger.new(LOG_PATH).info('Account Received') | |
message.inspect | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_contact_push_topic | |
# Create a PushTopic for subscribing to Contact changes. | |
contact_topic = @client.create!('PushTopic', | |
ApiVersion: '48.0', | |
Name: ENV['CONTACT_PUSH_TOPIC_NAME'], | |
Description: 'all contact records', | |
NotifyForOperations: 'All', | |
NotifyForFields: 'All', | |
Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, OtherPhone, AccountId, OwnerId, IsDeleted from Contact') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_account_push_topic | |
account_topic = @client.create!('PushTopic', | |
ApiVersion: '48.0', | |
Name: ENV['ACCOUNT_PUSH_TOPIC_NAME'], | |
Description: 'all account records', | |
NotifyForOperations: 'All', | |
NotifyForFields: 'All', | |
Query: 'select Id, Name, Phone, Type, BillingStreet,BillingCity, BillingState, BillingPostalCode, BillingCountry, Ownerid, ParentId, IsDeleted from Account') | |
Logger.new(LOG_PATH).info('Account Push Topic Id: ' + account_topic) | |
nd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Restforce uses faye as the underlying implementation for CometD. | |
require 'restforce' | |
require 'faye' | |
class SalesforceSubscriber | |
attr_reader :client | |
LOG_PATH = "#{Rails.root}/log/#{Rails.env}_salesforce.log" | |
# Initialize a client with your username/password/oauth token/etc. | |
def initialize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'cookiejar', git: 'https://github.com/MissionCapital/cookiejar.git' | |
gem 'faye', '0.8.9' | |
gem 'restforce', '~> 4.2.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"editor.tabSize": 2, | |
// Time (ms) to wait after keypress before running enabled linters. Ensures | |
// linters are only run when typing has finished and not for every keypress | |
"ruby.lintDebounceTime": 500, | |
// Basic settings: turn linter(s) on | |
"ruby.lint": { | |
"reek": true, | |
"rubocop": true, | |
"ruby": true, //Runs ruby -wc |