Created
August 12, 2020 19:16
-
-
Save rromanchuk/0fe5508e512e73ca8028caf6c3a30750 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# frozen_string_literal: true | |
class ApplicationController < ActionController::Base | |
def index | |
MyService.async_call(current_user) | |
end | |
end |
This file contains hidden or 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
# config/intitalizers/datadog-tracer.rb | |
require "ddtrace" | |
require "fast_jsonapi/instrumentation/skylight" | |
Datadog.configure do |c| | |
if Rails.env.production? | |
c.analytics_enabled = true | |
c.use :rails, service_name: "redact" | |
c.use :active_record, describes: :primary, service_name: 'write-db' | |
c.use :active_record, describes: :primary_replica, service_name: 'read-db' | |
c.env = "prod" | |
c.use :redis, analytics_enabled: true | |
c.use :aws, analytics_enabled: true | |
c.use :http, analytics_enabled: true | |
c.use :action_cable, analytics_enabled: true | |
c.use :redis, describes: { url: 'redis://redact/3' }, service_name: 'redact', analytics_enabled: true | |
c.use :redis, describes: { url: 'redis://redact/2' }, service_name: 'redact', analytics_enabled: true | |
c.use :redis, describes: { url: 'redis://redact/6' }, service_name: 'redact', analytics_enabled: true | |
c.use :redis, describes: { url: 'redis://redact/0' }, service_name: 'redact', analytics_enabled: true | |
c.use :redis, describes: { url: 'redis://redact' }, service_name: 'redact', analytics_enabled: true | |
elsif Rails.env.staging? | |
# snipped | |
else | |
# snipped | |
end | |
end | |
This file contains hidden or 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
ddtrace (0.38.0) | |
msgpack | |
rails (6.0.3.2) | |
actioncable (= 6.0.3.2) | |
actionmailbox (= 6.0.3.2) | |
actionmailer (= 6.0.3.2) | |
actionpack (= 6.0.3.2) | |
actiontext (= 6.0.3.2) | |
actionview (= 6.0.3.2) | |
activejob (= 6.0.3.2) | |
activemodel (= 6.0.3.2) | |
activerecord (= 6.0.3.2) | |
activestorage (= 6.0.3.2) | |
activesupport (= 6.0.3.2) | |
bundler (>= 1.3.0) | |
railties (= 6.0.3.2) |
This file contains hidden or 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
# app/services/my_service.rb | |
class MyService < Service | |
attr_reader :user | |
def initialize(user) | |
@user = user | |
end | |
def call | |
pp user | |
end | |
end |
This file contains hidden or 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
# app/services/service.rb | |
class Service | |
private_methods :new | |
class << self | |
def call(*args) | |
new(*args).call | |
end | |
def async_call(*args) | |
ServiceJob.perform_later(to_s, args) | |
end | |
end | |
end |
This file contains hidden or 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
# app/jobs/service_job.rb | |
class ServiceJob < ApplicationJob | |
queue_as :default | |
def perform(service_name, args) | |
service_name.constantize.call(*args) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.