From 7471f40e3f39b0ca96795e302a84b194dd936aa0 Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Wed, 9 Oct 2019 16:43:37 +0800 Subject: [PATCH] delete preview bulletins at 02:43 daily, using ruby process rather than cronjob --- announcement.gemspec | 2 ++ config/initializers/scheduler.rb | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 config/initializers/scheduler.rb diff --git a/announcement.gemspec b/announcement.gemspec index 29337cc..90c1f23 100644 --- a/announcement.gemspec +++ b/announcement.gemspec @@ -16,4 +16,6 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] s.test_files = Dir["test/**/*"] + + s.add_dependency "rufus-scheduler", "~> 3.6.0" end diff --git a/config/initializers/scheduler.rb b/config/initializers/scheduler.rb new file mode 100644 index 0000000..24f6666 --- /dev/null +++ b/config/initializers/scheduler.rb @@ -0,0 +1,9 @@ +require 'rufus-scheduler' + +scheduler = Rufus::Scheduler.new + +#return if defined?(Rails::Console) || Rails.env.test? || File.split($0).last == 'rake' + +scheduler.cron '43 2 * * *' do + system('bundle exec rake bulletin:remove_preview_bulletins') +end