Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File.open("/tmp/indexer_lock.tmp",'w') do |f|
- exit unless f.flock(File::LOCK_EX)
- end
- require 'rubygems'
- require 'daemons'
- Daemons.run('indexer.rb')
- loop do
- # code executing your indexing
- sleep INDEXING_INTERVAL
- end
- File.new("/tmp/foo.lock").flock( File::LOCK_NB | File::LOCK_EX )
- #!/usr/local/bin/bash
- #
- if ps -C $PROGRAM_NAME &> /dev/null ; then
- : #Program is already running.. appropriate action can be performed here (kill it?)
- else
- #Program is not running.. launch it.
- $PROGRAM_NAME
- fi
- tmp_file = File.expand_path(File.dirname(__FILE__)) + "/indexer.lock"
- if File.exists?(tmp_file)
- puts "quitting"
- exit
- else
- `touch #{tmp_file}`
- end
- .. do stuff ..
- File.delete(tmp_file)
- exit unless DATA.flock(File::LOCK_NB | File::LOCK_EX)
- # your script here
- __END__
- DO NOT REMOTE: required for the DATA object above.
- def the_method_my_cron_job_calls
- # something really expensive
- end
- lock_method :the_method_my_cron_job_calls
- LockMethod.config.storage = Redis.new([...]) # a remote RedisToGo instance, perhaps?
- def the_method_my_cron_job_calls
- # something really expensive
- end
- lock_method :the_method_my_cron_job_calls, (60*60) # automatically expire lock after an hour
Add Comment
Please, Sign In to add comment