Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Update readme #104

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ The above will start five workers in total:
* one listening on the `search_index, cache_warming` queue
* three listening on the `mailing` queue

### Multiple Servers/Roles
This can be useful for customizing Resque tasks in complex server environments.

### Multiple Servers/roles

You can also start up workers on multiple servers/roles:

Expand All @@ -89,6 +91,19 @@ The above will start four workers in total:
* one `search_index` on Server B
* one `search_index` on Server C

### Env Dynamic Schedule
To set env variable `DYNAMIC_SCHEDULE when` start scheduler use:

```ruby
set :resque_dynamic_schedule, true
```

When set this env, the command to start scheduler would

```bash
DYNAMIC_SCHEDULE=true bundle exec rake resque:scheduler
```

### Rails Environment

With Rails, Resque requires loading the Rails environment task to have access to your models, etc. (e.g. `QUEUE=* rake environment resque:work`). However, Resque is often used without Rails (and even if you are using Rails, you may not need/want to load the Rails environment). As such, the `environment` task is not automatically included.
Expand Down
11 changes: 6 additions & 5 deletions lib/capistrano-resque/capistrano_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def self.load_into(capistrano_config)
_cset(:workers, {"*" => 1})
_cset(:resque_kill_signal, "QUIT")
_cset(:interval, "5")
_cset(:resque_extra_env, "")
_cset(:resque_environment_task, false)
_cset(:resque_log_file, "/dev/null")
_cset(:resque_verbose, true)
Expand Down Expand Up @@ -47,10 +48,10 @@ def status_command

def start_command(queue, pid)
"cd #{current_path} && RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} QUEUE=\"#{queue}\" \
PIDFILE=#{pid} BACKGROUND=yes \
PIDFILE=#{pid} BACKGROUND=yes\
#{"VERBOSE=1 " if fetch(:resque_verbose)}\
INTERVAL=#{interval} \
nohup #{fetch(:bundle_cmd, "bundle")} exec rake \
INTERVAL=#{interval} #{resque_extra_env}\
#{fetch(:nohup_cmd, "")} #{fetch(:bundle_cmd, "bundle")} exec rake \
#{"environment " if fetch(:resque_environment_task)}\
resque:work #{output_redirection}"
end
Expand All @@ -77,12 +78,12 @@ def status_scheduler
end

def start_scheduler(pid)
"cd #{current_path} && RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} \
"cd #{current_path} && RACK_ENV=#{rails_env} #{resque_extra_env} RAILS_ENV=#{rails_env} \
PIDFILE=#{pid} BACKGROUND=yes \
#{"VERBOSE=1 " if fetch(:resque_verbose)}\
MUTE=1 \
#{"DYNAMIC_SCHEDULE=yes " if fetch(:resque_dynamic_schedule)}\
nohup #{fetch(:bundle_cmd, "bundle")} exec rake \
#{fetch(:nohup_cmd, "")} #{fetch(:bundle_cmd, "bundle")} exec rake \
#{"environment " if fetch(:resque_environment_task)}\
resque:scheduler #{output_redirection}"
end
Expand Down
5 changes: 3 additions & 2 deletions lib/capistrano-resque/tasks/capistrano-resque.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace :load do
task :defaults do
set :workers, {"*" => 1}
set :resque_extra_env, ""
set :resque_kill_signal, "QUIT"
set :interval, "5"
set :resque_environment_task, false
Expand Down Expand Up @@ -70,7 +71,7 @@ namespace :resque do
number_of_workers.times do
pid = "#{fetch(:resque_pid_path)}/resque_work_#{worker_id}.pid"
within current_path do
execute :nohup, %{#{SSHKit.config.command_map[:rake]} RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} QUEUE="#{queue}" PIDFILE=#{pid} BACKGROUND=yes #{"VERBOSE=1 " if fetch(:resque_verbose)}INTERVAL=#{fetch(:interval)} #{"environment " if fetch(:resque_environment_task)}resque:work #{output_redirection}}
execute %{cd #{release_path} && #{SSHKit.config.command_map[:rake]} #{fetch(:resque_extra_env)} RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} QUEUE="#{queue}" PIDFILE=#{pid} BACKGROUND=yes #{"VERBOSE=1 " if fetch(:resque_verbose)}INTERVAL=#{fetch(:interval)} #{"environment " if fetch(:resque_environment_task)}resque:work #{output_redirection}}
end
worker_id += 1
end
Expand Down Expand Up @@ -130,7 +131,7 @@ namespace :resque do
create_pid_path
pid = "#{fetch(:resque_pid_path)}/scheduler.pid"
within current_path do
execute :nohup, %{#{SSHKit.config.command_map[:rake]} RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} PIDFILE=#{pid} BACKGROUND=yes #{"VERBOSE=1 " if fetch(:resque_verbose)}MUTE=1 #{"DYNAMIC_SCHEDULE=yes " if fetch(:resque_dynamic_schedule)}#{"environment " if fetch(:resque_environment_task)}resque:scheduler #{output_redirection}}
execute %{cd #{release_path} && #{SSHKit.config.command_map[:rake]} #{fetch(:resque_extra_env)} RACK_ENV=#{rails_env} RAILS_ENV=#{rails_env} PIDFILE=#{pid} BACKGROUND=yes #{"VERBOSE=1 " if fetch(:resque_verbose)}MUTE=1 #{"DYNAMIC_SCHEDULE=yes " if fetch(:resque_dynamic_schedule)}#{"environment " if fetch(:resque_environment_task)}resque:scheduler #{output_redirection}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation

end
end
end
Expand Down