Skip to content

Instantly share code, notes, and snippets.

@fred
Forked from vjfrancois/clockwork.cap
Created April 22, 2014 11:13
Show Gist options
  • Select an option

  • Save fred/11174610 to your computer and use it in GitHub Desktop.

Select an option

Save fred/11174610 to your computer and use it in GitHub Desktop.

Revisions

  1. @vjfrancois vjfrancois revised this gist Apr 4, 2014. 1 changed file with 94 additions and 24 deletions.
    118 changes: 94 additions & 24 deletions clockwork.cap
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,103 @@
    after "deploy:stop", "clockwork:stop"
    after "deploy:start", "clockwork:start"
    after "deploy:restart", "clockwork:restart"
    namespace :workers do
    namespace :clockwork do
    desc "Stop clockwork"
    task :stop do
    on roles(:app) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} stop"
    end
    end
    end
    end

    set :cw_log_file, "#{shared_path}/log/clockwork.log"
    set :cw_pid_file, "#{shared_path}/tmp/pids/clockwork.pid"
    desc "Clockwork status"
    task :status do
    on roles(:app) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} status"
    end
    end
    end
    end

    namespace :clockwork do
    desc "Stop clockwork"
    task :stop, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} --stop || true"
    end
    desc "Start clockwork"
    task :start do
    on roles(:app) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} start"
    end
    end
    end
    end

    desc "Clockwork status"
    task :status, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} --verbose --running || true"
    end
    desc "Restart clockwork"
    task :restart do
    on roles(:app) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} restart"
    end
    end
    end
    end

    desc "Start clockwork"
    task :start, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} -- bundle exec clockwork lib/clockwork.rb"
    end
    def cw_log_dir
    "#{shared_path}/log"
    end
    def cw_pid_dir
    "#{shared_path}/tmp/pids"
    end

    desc "Restart clockwork"
    task :restart, :roles => :app, :on_no_matching_servers => :continue do
    stop
    start

    def rails_env
    fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
    end
    end

    def rails_env
    fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
    namespace :delayed_job do
    def args
    fetch(:delayed_job_args, "") #Useful for queuing on specific servers
    end

    def delayed_job_roles
    fetch(:delayed_job_server_role, :app)
    end

    desc 'Stop the delayed_job process'
    task :stop do
    on roles(delayed_job_roles) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :'script/delayed_job', :stop
    end
    end
    end
    end

    desc 'Start the delayed_job process'
    task :start do
    on roles(delayed_job_roles) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :'script/delayed_job', args, :start
    end
    end
    end
    end

    desc 'Restart the delayed_job process'
    task :restart do
    on roles(delayed_job_roles) do
    within release_path do
    with rails_env: fetch(:rails_env) do
    execute :bundle, :exec, :'script/delayed_job', args, :restart
    end
    end
    end
    end

    end
    end
  2. @vjfrancois vjfrancois revised this gist Apr 3, 2014. 2 changed files with 33 additions and 35 deletions.
    33 changes: 33 additions & 0 deletions clockwork.cap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    after "deploy:stop", "clockwork:stop"
    after "deploy:start", "clockwork:start"
    after "deploy:restart", "clockwork:restart"

    set :cw_log_file, "#{shared_path}/log/clockwork.log"
    set :cw_pid_file, "#{shared_path}/tmp/pids/clockwork.pid"

    namespace :clockwork do
    desc "Stop clockwork"
    task :stop, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} --stop || true"
    end

    desc "Clockwork status"
    task :status, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} --verbose --running || true"
    end

    desc "Start clockwork"
    task :start, :roles => :app, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{cw_log_file} --pidfile=#{cw_pid_file} -D #{current_path} -- bundle exec clockwork lib/clockwork.rb"
    end

    desc "Restart clockwork"
    task :restart, :roles => :app, :on_no_matching_servers => :continue do
    stop
    start
    end

    def rails_env
    fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
    end
    end
    35 changes: 0 additions & 35 deletions clockwork.rb
    Original file line number Diff line number Diff line change
    @@ -1,35 +0,0 @@
    after "deploy:stop", "clockwork:stop"
    after "deploy:start", "clockwork:start"
    after "deploy:restart", "clockwork:restart"

    namespace :clockwork do
    desc "Stop clockwork"
    task :stop, :roles => clockwork_roles, :on_error => :continue, :on_no_matching_servers => :continue do
    run "if [ -d #{current_path} ] && [ -f #{pid_file} ]; then cd #{current_path} && kill -INT `cat #{pid
    _file}` ; fi"
    end

    desc "Start clockwork"
    task :start, :roles => clockwork_roles, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{log_file} --pidfile=#{pid_file
    } -D #{current_path} -- bundle exec clockwork config/clockwork.rb"
    end

    desc "Restart clockwork"
    task :restart, :roles => clockwork_roles, :on_no_matching_servers => :continue do
    stop
    start
    end

    def rails_env
    fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
    end

    def log_file
    fetch(:clockwork_log_file, "#{current_path}/log/clockwork.log")
    end

    def pid_file
    fetch(:clockwork_pid_file, "#{current_path}/tmp/pids/clockwork.pid")
    end
    end
  3. Roger Campos created this gist Sep 6, 2012.
    35 changes: 35 additions & 0 deletions clockwork.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    after "deploy:stop", "clockwork:stop"
    after "deploy:start", "clockwork:start"
    after "deploy:restart", "clockwork:restart"

    namespace :clockwork do
    desc "Stop clockwork"
    task :stop, :roles => clockwork_roles, :on_error => :continue, :on_no_matching_servers => :continue do
    run "if [ -d #{current_path} ] && [ -f #{pid_file} ]; then cd #{current_path} && kill -INT `cat #{pid
    _file}` ; fi"
    end

    desc "Start clockwork"
    task :start, :roles => clockwork_roles, :on_no_matching_servers => :continue do
    run "daemon --inherit --name=clockwork --env='#{rails_env}' --output=#{log_file} --pidfile=#{pid_file
    } -D #{current_path} -- bundle exec clockwork config/clockwork.rb"
    end

    desc "Restart clockwork"
    task :restart, :roles => clockwork_roles, :on_no_matching_servers => :continue do
    stop
    start
    end

    def rails_env
    fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : ''
    end

    def log_file
    fetch(:clockwork_log_file, "#{current_path}/log/clockwork.log")
    end

    def pid_file
    fetch(:clockwork_pid_file, "#{current_path}/tmp/pids/clockwork.pid")
    end
    end