Skip to content

Commit

Permalink
Add in automatic batch running
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeese committed Oct 6, 2016
1 parent 7d98015 commit ccddb09
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ gem 'bootstrap_form'
gem 'rubyhorn', git: "https://github.com/avalonmediasystem/rubyhorn.git"
gem 'roo'
gem 'activerecord-session_store'
gem 'whenever', require: false
gem 'with_locking'

#MediaElement.js related
gem 'mediaelement_rails', git: 'https://github.com/avalonmediasystem/mediaelement_rails.git', branch: 'captions'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
chronic (0.10.2)
coderay (1.1.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -633,6 +634,9 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
whenever (0.9.4)
chronic (>= 0.6.3)
with_locking (1.0.2)
xml-simple (1.1.5)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand Down Expand Up @@ -708,6 +712,8 @@ DEPENDENCIES
sqlite3
uglifier (>= 1.3.0)
web-console (~> 2.0)
whenever
with_locking

BUNDLED WITH
1.13.1
7 changes: 7 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set :output, "log/whenever_cron.log"
job_type :locking_runner, "cd :path && :environment_variable=:environment script/locking_runner :lock_name :task :output"
job_type :locking_rake, "cd :path && :environment_variable=:environment script/locking_runner :lock_name bundle exec rake :task --silent :output"

every 1.minute do
locking_rake "avalon:batch:ingest", :lock_name => "batch_ingest"
end
14 changes: 14 additions & 0 deletions script/locking_runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#
# Usage: locking_runner process_name command arg arg arg...
#

SEMAPHORE=$1
LOCKFILE=tmp/pids/$SEMAPHORE
shift

if ( set -o noclobber; echo "$$" > "$LOCKFILE") 2> /dev/null;
then
trap 'rm -f "$LOCKFILE"; exit 255' INT TERM EXIT
"$@" || true #run the command
fi

0 comments on commit ccddb09

Please sign in to comment.