Commit 8c6988805ef1474bfd7dcd8f92524f9eaf971eb8

Authored by Antonio Terceiro
2 parents bf2cbbd3 348b6cb5

Merge branch 'whenever-multitenancy' into 'master'

Fixes whenever in production for a multitenancy setup

Each cronjob has to run for all production environments. Currently they are
only running for the environment named production so it doesn't work in a
multitenancy setup.

I use `whenever --update-crontab` to append jobs for each environment, using the 
environment name as a whenever identifier, and then I have to clean the crontab of each
environment generated jobs using the same identifier.

See merge request !705
Showing 2 changed files with 26 additions and 3 deletions   Show diff stats
script/production
@@ -48,7 +48,6 @@ do_start() { @@ -48,7 +48,6 @@ do_start() {
48 bundle exec rake db:migrate SCHEMA=/dev/null 48 bundle exec rake db:migrate SCHEMA=/dev/null
49 clear_cache 49 clear_cache
50 environments_loop start 50 environments_loop start
51 - bundle exec whenever --write-crontab --set 'environment=production'  
52 app_server_start 51 app_server_start
53 } 52 }
54 53
@@ -63,8 +62,6 @@ do_stop() { @@ -63,8 +62,6 @@ do_stop() {
63 62
64 environments_loop stop || 63 environments_loop stop ||
65 stop_via_pid_file tmp/pids/delayed_job.pid tmp/pids/delayed_job.*.pid tmp/pids/feed-updater.*.pid 64 stop_via_pid_file tmp/pids/delayed_job.pid tmp/pids/delayed_job.*.pid tmp/pids/feed-updater.*.pid
66 -  
67 - bundle exec whenever --clear-crontab  
68 } 65 }
69 66
70 do_restart() { 67 do_restart() {
@@ -97,10 +94,12 @@ environments_loop() { @@ -97,10 +94,12 @@ environments_loop() {
97 env=$(basename $environment | cut -d. -f1) 94 env=$(basename $environment | cut -d. -f1)
98 RAILS_ENV=$env bundle exec ./script/delayed_job -i $env "$action" 95 RAILS_ENV=$env bundle exec ./script/delayed_job -i $env "$action"
99 RAILS_ENV=$env bundle exec ./script/feed-updater "$action" -i $env 96 RAILS_ENV=$env bundle exec ./script/feed-updater "$action" -i $env
  97 + ./script/whenever $action $env
100 done 98 done
101 else 99 else
102 bundle exec ./script/delayed_job "$action" 100 bundle exec ./script/delayed_job "$action"
103 bundle exec ./script/feed-updater "$action" 101 bundle exec ./script/feed-updater "$action"
  102 + ./script/whenever $action
104 fi 103 fi
105 } 104 }
106 105
script/whenever 0 → 100755
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +#!/bin/sh
  2 +
  3 +ACTION="$1"
  4 +ENV="$2"
  5 +if [ -z "$ENV" ]; then
  6 + ENV='production'
  7 +fi
  8 +
  9 +do_start(){
  10 + bundle exec whenever --update-crontab $ENV --set "environment=$ENV"
  11 +}
  12 +
  13 +do_stop(){
  14 + bundle exec whenever --clear-crontab $ENV
  15 +}
  16 +case "$ACTION" in
  17 + start|stop)
  18 + do_$ACTION
  19 + ;;
  20 + *)
  21 + echo "usage: $0 start|stop [environment]"
  22 + exit 1
  23 + ;;
  24 +esac