Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lyalg0rithm committed May 11, 2015
0 parents commit 6f6032a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in capistrano-rvm.gemspec
gemspec
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
19 changes: 19 additions & 0 deletions capistrano-clockwork.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |s|
s.name = 'capistrano-clockwork'
s.version = '0.0.2'
s.date = '2015-05-12'
s.summary = "Capistrano plugin to manage clockwork"
s.description = "Capistrano plugin to manage clockwork"
s.authors = ["Suraj Shirvankar"]
s.email = '[email protected]'
s.files = ["lib/capistrano-clockwork.rb"]
s.homepage = "http://github.com/h0lyalg0rithm/capistrano-clockwork"
s.license = 'MIT'

s.files = `git ls-files`.split($/)
s.require_path= ["lib"]
s.add_dependency 'capistrano', '~> 3.1'
end
Empty file added lib/capistrano-clockwork.rb
Empty file.
1 change: 1 addition & 0 deletions lib/capistrano/clockwork.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load File.expand_path("../tasks/capistrano-clockwork.rake", __FILE__)
78 changes: 78 additions & 0 deletions lib/capistrano/tasks/capistrano-clockwork.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace :load do
task :defaults do
set :clockwork_default_hooks, -> { true }
set :clockwork_file, -> { "lib/clockwork.rb" }
end
end

namespace :deploy do
before :starting, :check_sidekiq_hooks do
invoke 'clockwork:add_default_hooks' if fetch(:clockwork_default_hooks)
end
after :publishing, :restart_sidekiq do
invoke 'clockwork:restart' if fetch(:clockwork_default_hooks)
end
end

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 #{fetch(:clockwork_file)} --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} --log stop"
end
end
end
end

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 #{fetch(:clockwork_file)} --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} --log status"
end
end
end
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 #{fetch(:clockwork_file)} --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} --log start"
end
end
end
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 #{fetch(:clockwork_file)} --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} --log restart"
end
end
end
end

def cw_log_dir
"#{shared_path}/log"
end
def cw_pid_dir
"#{shared_path}/tmp/pids"
end

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

task :add_default_hooks do
after 'deploy:stop', 'clockwork:stop'
after 'deploy:start', 'clockwork:start'
after 'deploy:restart', 'clockwork:restart'
end
end

0 comments on commit 6f6032a

Please sign in to comment.