Sha256: 1da68e8940b8ae7ce436a60f5e73e9e1d8a490c499272534d62de4c5c0211659
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
require 'erb' require 'ostruct' require 'tempfile' require 'whenever' require 'activerecord_session_cleaner/session' namespace :activerecord_session_cleaner do namespace :crontab do class ERBStruct < OpenStruct def render(template) ERB.new(template).result(binding) end end def whenever_identifier(application_name = nil) application_name ||= File.basename(Dir.pwd) "#{application_name}-activerecord_session_cleaner" end DEFAULT_ENVIRONMENT = 'development' desc 'Setup/update cron for session cleanup' task :update, [:application_name, :days_to_keep] => :environment do |t, args| template_data = ERBStruct.new(days_to_keep: args.days_to_keep) template = File.read(File.expand_path('../../templates/schedule.rb.erb', __FILE__)) schedule_file = Tempfile.new('activerecord_session_cleaner-schedule') schedule_file.write template_data.render(template) schedule_file.close(false) Whenever::CommandLine.execute({ update: true, identifier: whenever_identifier(args.application_name), file: schedule_file.path, set: "environment=#{ENV['RAILS_ENV'] || DEFAULT_ENVIRONMENT}", }) schedule_file.unlink end desc 'Remove cleanup cron for session cleanup' task :clear, [:application_name] => :environment do |t, args| Whenever::CommandLine.execute({ clear: true, identifier: whenever_identifier(args.application_name), }) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activerecord_session_cleaner-1.0.1 | lib/activerecord_session_cleaner/tasks/crontab.rake |
activerecord_session_cleaner-1.0.0 | lib/activerecord_session_cleaner/tasks/crontab.rake |