From f65f24be0baedc958af0357a78edb0a569d02f76 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 24 May 2021 23:55:27 -0500 Subject: [PATCH] docker: add cron service to compose file. --- Gemfile | 1 + Gemfile.lock | 4 ++++ config/initializers/clockwork.rb | 22 ++++++++++++++++++++++ docker-compose.yaml | 18 ++++++++++++++---- lib/tasks/danbooru.rake | 5 +++++ 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 config/initializers/clockwork.rb diff --git a/Gemfile b/Gemfile index 589bd32eb..19cd061f7 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ gem 'ed25519' gem 'bcrypt_pbkdf' # https://github.com/net-ssh/net-ssh/issues/565 gem 'terminal-table' gem 'newrelic_rpm', require: false +gem 'clockwork' group :production, :staging do gem 'unicorn', :platforms => :ruby diff --git a/Gemfile.lock b/Gemfile.lock index ab53a6f3c..ca2d83763 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,9 @@ GEM xpath (~> 3.2) childprocess (3.0.0) chronic (0.10.2) + clockwork (2.0.4) + activesupport + tzinfo codecov (0.5.2) simplecov (>= 0.15, < 0.22) coderay (1.1.3) @@ -494,6 +497,7 @@ DEPENDENCIES capistrano-rbenv capistrano3-unicorn capybara + clockwork codecov daemons delayed_job diff --git a/config/initializers/clockwork.rb b/config/initializers/clockwork.rb new file mode 100644 index 000000000..143c9543d --- /dev/null +++ b/config/initializers/clockwork.rb @@ -0,0 +1,22 @@ +# Define cronjobs using the clockwork gem; see https://github.com/Rykian/clockwork. +# Use `bin/rails danbooru:cron` to start the cron process. +# +# See also `app/logical/danbooru_maintenance.rb`. + +module Clockwork + every(1.hour, "hourly", at: "**:00") do + DanbooruMaintenance.hourly + end + + every(1.day, "daily", at: "00:00") do + DanbooruMaintenance.daily + end + + every(1.week, "weekly", at: "Sunday 00:00") do + DanbooruMaintenance.weekly + end + + every(1.month, "monthly", at: "00:00") do + DanbooruMaintenance.monthly + end +end diff --git a/docker-compose.yaml b/docker-compose.yaml index 1be66efe5..5066a78f2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -21,7 +21,7 @@ version: "3.4" services: danbooru: - image: danbooru + image: evazion/danbooru ports: - "80:3000" environment: @@ -36,15 +36,25 @@ services: command: ["bash", "-c", "bin/rails db:setup; bin/rails db:migrate && bin/rails server -b 0.0.0.0"] user: root - delayed_jobs: - image: danbooru + cron: + image: evazion/danbooru environment: - RAILS_ENV=production - DATABASE_URL=postgresql://danbooru@postgres/danbooru - DANBOORU_CANONICAL_URL=http://localhost depends_on: - danbooru - command: ["bash", "-c", "bin/wait-for-http http://danbooru:3000 3s && bin/delayed_job run"] + command: ["bash", "-c", "bin/wait-for-http http://danbooru:3000 5s && bin/rails danbooru:cron"] + + delayed_jobs: + image: evazion/danbooru + environment: + - RAILS_ENV=production + - DATABASE_URL=postgresql://danbooru@postgres/danbooru + - DANBOORU_CANONICAL_URL=http://localhost + depends_on: + - danbooru + command: ["bash", "-c", "bin/wait-for-http http://danbooru:3000 5s && bin/delayed_job run"] postgres: image: evazion/postgres diff --git a/lib/tasks/danbooru.rake b/lib/tasks/danbooru.rake index 0cc9fc11c..33761b928 100644 --- a/lib/tasks/danbooru.rake +++ b/lib/tasks/danbooru.rake @@ -1,4 +1,9 @@ namespace :danbooru do + desc "Run the cronjob scheduler" + task cron: :environment do + Clockwork::run + end + namespace :docker do # Note that uncommited changes won't be included in the image; commit # changes first before building the image.