diff --git a/Gemfile b/Gemfile index b46ddd64..e59f27ff 100644 --- a/Gemfile +++ b/Gemfile @@ -57,7 +57,7 @@ gem 'redis-rails' gem 'reverse_markdown', git: 'https://0xacab.org/sutty/reverse_markdown.git' gem 'rubyzip' gem 'rugged' -gem 'sidekiq' +gem 'sucker_punch' gem 'terminal-table' gem 'validates_hostname' gem 'webpacker' diff --git a/Gemfile.lock b/Gemfile.lock index 186a5d4a..9d81b2c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,7 +107,6 @@ GEM commonmarker (0.20.1) ruby-enum (~> 0.5) concurrent-ruby (1.1.5) - connection_pool (2.2.2) crass (1.0.4) database_cleaner (1.7.0) devise (4.7.1) @@ -252,8 +251,6 @@ GEM pundit (2.1.0) activesupport (>= 3.0.0) rack (2.0.7) - rack-protection (2.0.7) - rack rack-proxy (0.6.5) rack rack-test (1.1.0) @@ -360,11 +357,6 @@ GEM selenium-webdriver (3.142.4) childprocess (>= 0.5, < 3.0) rubyzip (~> 1.2, >= 1.2.2) - sidekiq (6.0.0) - connection_pool (>= 2.2.2) - rack (>= 2.0.0) - rack-protection (>= 2.0.0) - redis (>= 4.1.0) simpleidn (0.1.1) unf (~> 0.1.4) spring (2.1.0) @@ -382,6 +374,8 @@ GEM sshkit (1.20.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + sucker_punch (2.1.2) + concurrent-ruby (~> 1.0) sysexits (1.2.0) temple (0.8.1) terminal-table (1.8.0) @@ -471,10 +465,10 @@ DEPENDENCIES rugged sass-rails (~> 5.0) selenium-webdriver - sidekiq spring spring-watcher-listen (~> 2.0.0) sqlite3 + sucker_punch terminal-table turbolinks (~> 5) uglifier (>= 1.3.0) diff --git a/Procfile b/Procfile index 50be8a61..c2eadd25 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,2 @@ migrate: if test -f data/production.sqlite3; then bundle exec rake db:migrate db:seed ; else bundle exec rake db:setup ; fi sutty: bundle exec puma -d config.ru -sidekiq: bundle exec sidekiq -t 1 diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index f9053f09..23b15304 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -70,7 +70,7 @@ class SitesController < ApplicationController authorize site # XXX: Convertir en una máquina de estados? - DeployWorker.perform_async site.id if site.enqueue! + DeployJob.perform_async site.id if site.enqueue! redirect_to sites_path end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d92ffddc..2555d2ac 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +# Base para trabajos class ApplicationJob < ActiveJob::Base + include SuckerPunch::Job end diff --git a/app/workers/deploy_worker.rb b/app/jobs/deploy_job.rb similarity index 95% rename from app/workers/deploy_worker.rb rename to app/jobs/deploy_job.rb index 15a31549..ced60d3e 100644 --- a/app/workers/deploy_worker.rb +++ b/app/jobs/deploy_job.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true # Realiza el deploy de un sitio -class DeployWorker - include Sidekiq::Worker - +class DeployJob < ApplicationJob def perform(site) site = Site.find(site) site.update_attribute :status, 'building' diff --git a/bin/sidekiq b/bin/sidekiq deleted file mode 100755 index 5d97d883..00000000 --- a/bin/sidekiq +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'sidekiq' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path('bundle', __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort( - 'Your `bin/bundle` was not generated by Bundler, so this binstub - cannot run. Replace `bin/bundle` by running `bundle binstubs - bundler --force`, then run this command again.' - ) - end -end - -require 'rubygems' -require 'bundler/setup' - -load Gem.bin_path('sidekiq', 'sidekiq') diff --git a/bin/sidekiqctl b/bin/sidekiqctl deleted file mode 100755 index 10eb2f4f..00000000 --- a/bin/sidekiqctl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'sidekiqctl' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path('bundle', __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort( - 'Your `bin/bundle` was not generated by Bundler, so this binstub - cannot run. Replace `bin/bundle` by running `bundle binstubs - bundler --force`, then run this command again.' - ) - end -end - -require 'rubygems' -require 'bundler/setup' - -load Gem.bin_path('sidekiq', 'sidekiqctl') diff --git a/config/environments/production.rb b/config/environments/production.rb index a450589f..14042423 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -67,7 +67,7 @@ Rails.application.configure do # Use a real queuing backend for Active Job (and separate queues per # environment) - config.active_job.queue_adapter = :sidekiq + config.active_job.queue_adapter = :sucker_punch config.active_job.queue_name_prefix = "sutty_#{Rails.env}" config.action_mailer.perform_caching = false diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb deleted file mode 100644 index 0ebf8b8c..00000000 --- a/config/initializers/sidekiq.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -Sidekiq.configure_server do |config| - config.redis = { - url: ENV.fetch('REDIS_SERVER', 'redis://localhost:6379/1') - } -end - -Sidekiq.configure_client do |config| - config.redis = { - url: ENV.fetch('REDIS_CLIENT', 'redis://localhost:6379/1') - } -end diff --git a/monit.conf b/monit.conf index b9029baa..4d34d69c 100644 --- a/monit.conf +++ b/monit.conf @@ -1,5 +1,5 @@ check process sutty with pidfile /srv/http/tmp/puma.pid - start program = "/bin/sh -c 'cd /srv/http && foreman start migrate && foreman start sutty && foreman start sidekiq'" as uid app + start program = "/bin/sh -c 'cd /srv/http && foreman start migrate && foreman start sutty'" as uid app stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" check program sync_assets diff --git a/test/controllers/sites_controller_test.rb b/test/controllers/sites_controller_test.rb index 3697a853..19b98854 100644 --- a/test/controllers/sites_controller_test.rb +++ b/test/controllers/sites_controller_test.rb @@ -88,14 +88,11 @@ class SitesControllerTest < ActionDispatch::IntegrationTest end test 'se pueden encolar' do - Sidekiq::Testing.fake! - post site_enqueue_url(@site), headers: @authorization - assert DeployWorker.jobs.count.positive? - assert @site.reload.enqueued? - - Sidekiq::Testing.inline! + assert File.directory?(@site.deploys.first.destination) + assert File.exist?(File.join(@site.deploys.first.destination, + 'index.html')) end test 'se pueden actualizar' do diff --git a/test/workers/deploy_worker_test.rb b/test/jobs/deploy_job_test.rb similarity index 79% rename from test/workers/deploy_worker_test.rb rename to test/jobs/deploy_job_test.rb index 53e44d94..6d1d321d 100644 --- a/test/workers/deploy_worker_test.rb +++ b/test/jobs/deploy_job_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class DeployWorkerTest < ActiveSupport::TestCase +class DeployJobTest < ActiveSupport::TestCase test 'se puede compilar' do rol = create :rol site = rol.site @@ -8,7 +8,7 @@ class DeployWorkerTest < ActiveSupport::TestCase site.save - DeployWorker.perform_async(site.id) + DeployJob.perform_async(site.id) assert_not ActionMailer::Base.deliveries.empty? diff --git a/test/test_helper.rb b/test/test_helper.rb index 437b0dab..cf139953 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,9 +3,7 @@ require File.expand_path('../config/environment', __dir__) require 'rails/test_help' require 'open3' - -require 'sidekiq/testing' -Sidekiq::Testing.inline! +require 'sucker_punch/testing/inline' # rubocop:disable Style/ClassAndModuleChildren class ActiveSupport::TestCase