Code Monkey home page Code Monkey logo

Comments (4)

kntmrkm avatar kntmrkm commented on September 7, 2024

sorry guys.
I found this doc, https://github.com/chanks/que/blob/master/docs/advanced_setup.md.

but, I don't know how to setting my unicorn.rb.
Please tell me about setting with unicorn.

from que.

chanks avatar chanks commented on September 7, 2024

Hello -

I don't believe anyone has tried to get Que working with Unicorn yet. I believe you would want to set config.que.mode = :off in your application configuration and then set Que.mode = :async in each worker after forking, but I don't have an example of how you'd do that with Unicorn. If you figure it out, please let me know and I'll add it to the docs.

from que.

kntmrkm avatar kntmrkm commented on September 7, 2024

OK, setting verified.
Please check bellow.
(I have no skill to pull request for doc. sorry.)

config/application.rb

require File.expand_path('../boot', __FILE__)
・・・・#omit
require "que"
Bundler.require(:default, Rails.env)
module App
  class Application < Rails::Application
    ・・・・#omit
    # Que
    Que.mode = :off
    ・・・・#omit
end

and,

config/unicorn.rb
(this config include my original.)

APP_DIR = File.expand_path("../../", __FILE__)
preload_app true
worker_processes (ENV['RAILS_ENV'] == 'development' ? 1 : 2)
working_directory APP_DIR
timeout 30

unless ENV['RAILS_ENV'] == 'development'
  listen File.expand_path("tmp/sockets/unicorn.sock", ENV['RAILS_ROOT']), :backlog => 64
else
  listen 3000
end
pid File.expand_path("tmp/pids/unicorn.pid", ENV['RAILS_ROOT'])

stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])

before_fork do |server, worker|
  old_pid = "#{ server.config[:pid] }.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  # Que
  require 'yaml'
  require "active_record"
  require 'que'
  config = YAML.load(File.read("config/database.yml"))["#{ENV['RAILS_ENV']}"]
  ActiveRecord::Base.establish_connection(config)
  Que.connection = ActiveRecord
  Que.mode = :async

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

thank you so much.
It's very good.

from que.

chanks avatar chanks commented on September 7, 2024

Good! I'm glad you got it working. I'll shorten up your configuration and add it to the docs soon.

from que.

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.