# frozen_string_literal: true

server 'api.feedirss.com', user: 'deploy', roles: %w[app db web]

set :application, 'feedi'
set :repo_url, 'git@github.com:davidesantangelo/feedirss-api.git'

# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"

append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'

# Only keep the last 5 releases to save disk space
set :keep_releases, 5
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:production)}" }

# Optionally, you can symlink your database.yml and/or secrets.yml file from the shared directory during deploy
# This is useful if you don't want to use ENV variables
# append :linked_files, 'config/database.yml', 'config/secrets.yml'

Rake::Task['sidekiq:stop'].clear_actions
Rake::Task['sidekiq:start'].clear_actions
Rake::Task['sidekiq:restart'].clear_actions
namespace :sidekiq do
  task :stop do
    on roles(:app) do
      execute :sudo, :systemctl, :stop, :sidekiq
    end
  end
  task :start do
    on roles(:app) do
      execute :sudo, :systemctl, :start, :sidekiq
    end
  end
  task :restart do
    on roles(:app) do
      execute :sudo, :systemctl, :restart, :sidekiq
    end
  end
end
