diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 57567d6..8942d13 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -9,6 +9,8 @@ fi # If running the rails server then create or migrate existing database if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then ./bin/rails db:prepare + echo "Warming up caches for production deployment..." + ./bin/rails cache:warmup fi exec "${@}" diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake new file mode 100644 index 0000000..2d08428 --- /dev/null +++ b/lib/tasks/cache.rake @@ -0,0 +1,37 @@ +namespace :cache do + desc "Warm up all caches for deployment and healthchecks" + task warmup: :environment do + puts "Starting cache warmup for deployment..." + + cache_jobs = [ + Cache::CurrentlyHackingJob, + Cache::ActiveUsersGraphDataJob, + Cache::HomeStatsJob, + Cache::HeartbeatCountsJob, + Cache::ActiveProjectsJob, + Cache::MinutesLoggedJob, + Cache::SetupSocialProofJob, + Cache::UsageSocialProofJob + ] + + cache_jobs.each do |job_class| + puts "Running #{job_class.name}..." + begin + job_class.perform_now + puts "✓ #{job_class.name} completed" + rescue => e + puts "✗ #{job_class.name} failed: #{e.message}" + Rails.logger.error("Cache warmup failed for #{job_class.name}: #{e.class.name} #{e.message}") + end + end + + puts "Cache warmup completed!" + end + + desc "Clear all application caches" + task clear: :environment do + puts "Clearing all application caches..." + Rails.cache.clear + puts "✓ All caches cleared" + end +end