diff --git a/Capfile b/Capfile index 28e4a8e..7e9c9a1 100644 --- a/Capfile +++ b/Capfile @@ -40,5 +40,7 @@ install_plugin Capistrano::Puma # Default puma tasks # install_plugin Capistrano::Puma::Monit # if you need the monit tasks # install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template +require "whenever/capistrano" + # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile index ea40166..ea6eb71 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,7 @@ gem 'bcrypt', '~> 3.1.7' gem 'open4' gem 'naught' +gem 'whenever', require: false gem 'octicons' diff --git a/Gemfile.lock b/Gemfile.lock index 646924f..6ce9113 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,6 +91,7 @@ GEM chromedriver-helper (1.2.0) archive-zip (~> 0.10) nokogiri (~> 1.8) + chronic (0.10.2) coderay (1.1.2) concurrent-ruby (1.0.5) crass (1.0.4) @@ -308,6 +309,8 @@ GEM websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) + whenever (0.10.0) + chronic (>= 0.6.3) xpath (3.0.0) nokogiri (~> 1.8) @@ -357,6 +360,7 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (>= 3.3.0) webpacker (~> 3.5) + whenever RUBY VERSION ruby 2.5.1p57 diff --git a/app/services/notifier.rb b/app/services/notifier.rb index 5927cde..36836fd 100644 --- a/app/services/notifier.rb +++ b/app/services/notifier.rb @@ -1,3 +1,5 @@ +require "notifier/processor" + module Notifier class << self def process_all(configuration = nil) diff --git a/config/deploy.rb b/config/deploy.rb index cf3712d..e1cec8c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -43,3 +43,5 @@ append :linked_files, # Uncomment the following to require manually verifying the host key before first deploy. # set :ssh_options, verify_host_key: :secure + +set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 0000000..709286e --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,27 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +set :output, standard: "log/cron.log" + +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +# Learn more: http://github.com/javan/whenever + +every 1.day, at: '4:30 am', roles: [:app] do + rake "checks:sync_dates" +end + +every 1.day, at: '10:30 am', roles: [:app] do + rake "notifications:send_all" +end diff --git a/lib/tasks/notifications.rake b/lib/tasks/notifications.rake new file mode 100644 index 0000000..1bb02f8 --- /dev/null +++ b/lib/tasks/notifications.rake @@ -0,0 +1,8 @@ +# require "services/notifier" + +namespace :notifications do + desc "Send all notifications after checks have been performend" + task send_all: :environment do + Notifier.process_all + end +end