Giter Site home page Giter Site logo

Comments (3)

shanemcd avatar shanemcd commented on July 23, 2024

Update: I've identified that the issue is caused by using unicorn-rails in development.

This code allows for an optional config file to be created at config/unicorn/#{environment}.rb.

I attempted to copy the after_fork code into this file, but does not resolve the issue. The thread is still dead.

from analytics-ruby.

calvinfo avatar calvinfo commented on July 23, 2024

@shanemcd any chance you can send me what your config/unicorn looks like?

using my super janky rails test project, I was able to see events being sent to segment.io: https://github.com/calvinfo/segmentio-rails-test/blob/master/config/unicorn/development.rb

we aren't really rails guys though, so there could be something obvious which I'm missing. thanks for the detailed report so far! :)

from analytics-ruby.

shanemcd avatar shanemcd commented on July 23, 2024

I am not quite sure what was going on yesterday, but here is what worked for me:

In an initializer:

Analytics = AnalyticsRuby

This was necessary because assigning the alias in the unicorn config was throwing uninitialized constant WhateverController::Analytics

I'm not sure how you got this to work, but the only thing I can think of is a difference between Rails 3 and Rails 4?

Moving on...

In config/unicorn/development.rb:

worker_processes 3
timeout 30
preload_app true

before_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    ::Rails.logger.info('Unicorn is about to fork workers, so disconnecting from the database in this process')
  end
  sleep 1
end

after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    ::Rails.logger.info('Unicorn worker process: connecting to the database')
  end

  if defined?(Analytics)
    Analytics.init({
      secret: Settings.segment_io.try(:secret_key),
      on_error: Proc.new { |status, msg| print msg }
    })
    ::Rails.logger.info('Initializing Segment.io Library')
  end
end

from analytics-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.