Download resque working without rails?

Resque tasks that I don't depend on anything in Rails, but it's hard for me to get started without env rails. I saw this post but it didn’t help ( ruby resque without loading the rails environment )

Here is my current rake file:

require "resque/tasks" task "resque:setup" do root_path = "#{File.dirname(__FILE__)}/../.." require "#{root_path}/app/workers/myworker.rb" end #task "resque:setup" => :environment 

The recorded task will load Rails env and everything works, but that’s not what I want. When running rake resque:work I get this error:

 rake aborted! No such file to load -- application_controller Tasks: TOP => resque:work => resque:preload 
+4
source share
2 answers

If you just added the lib / tasks / resque.rake file and did not change your Rakefile, you will still load the Rails environment when you call rake resque: work. Try this for Rakefile:

 unless ENV['RESQUE_WORKER'] == 'true' require File.expand_path('../config/application', __FILE__) My::Application.load_tasks else ROOT_PATH = File.expand_path("..", __FILE__) load File.join(ROOT_PATH, 'lib/tasks/resque.rake') end 

And then this is for your resque.rake file:

 require "resque/tasks" task "resque:setup" do raise "Please set your RESQUE_WORKER variable to true" unless ENV['RESQUE_WORKER'] == "true" root_path = "#{File.dirname(__FILE__)}/../.." require "#{root_path}/app/workers/myworker.rb" end 

Then call rake resque:work RESQUE_WORKER=true

+6
source

I named the link here. It worked fine for me:

This error was resolved by running

 $> QUEUE=* rake environment resque:work 

a cleaner solution was to define the rake problem:

 task "resque:setup" => :environment do ENV['QUEUE'] ||= '*' #for redistogo on heroku http://stackoverflow.com/questions/2611747/rails-resque-workers-fail-with-pgerror-server-closed-the-connection-unexpectedl Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end 

and now

 rake resque:work 

Works great

Thanks.

-1
source

Source: https://habr.com/ru/post/1402902/


All Articles