Class: RQ::Rotater
- Inherits:
-
MainHelper
- Object
- MainHelper
- RQ::Rotater
- Defined in:
- lib/rq/rotater.rb
Constant Summary
Constants included from Logging
Logging::DIV0, Logging::DIV1, Logging::DIV2, Logging::DIV3, Logging::EOL, Logging::SEC0, Logging::SEC1, Logging::SEC2, Logging::SEC3
Instance Attribute Summary
Attributes inherited from MainHelper
#argv, #cmd, #dot_rq_dir, #env, #fields, #job_stdin, #loops, #main, #mode, #options, #program, #q, #qpath, #quiet, #stdin
Instance Method Summary collapse
-
#cp_r(srcdir, dstdir) ⇒ Object
the cp_r should never fail, so we build in another attempt under failing conditions.
-
#rotate ⇒ Object
–{{{.
Methods inherited from MainHelper
#dumping_yaml_tuples, #field_match, #init_job_stdin!, #initialize, #loadio, #loadyaml, #set_q
Methods included from Logging
Methods included from Logging::LogMethods
#debug, #error, #fatal, #info, #logerr, #logger, #logger=, #warn
Methods included from Util
#alive?, append_features, #btrace, #columnize, #defval, #emsg, #erreq, #errmsg, #escape, #escape!, #exec, export, #fork, #getopt, #hashify, #hms, #host, #hostname, #klass, #maim, #mcp, #realpath, #stamptime, #system, #timestamp, #tmpnam, #uncache, #which_ruby
Constructor Details
This class inherits a constructor from RQ::MainHelper
Instance Method Details
#cp_r(srcdir, dstdir) ⇒ Object
the cp_r should never fail, so we build in another attempt under failing conditions
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rq/rotater.rb', line 75 def cp_r srcdir, dstdir #--{{{ attempts = 0 loop do begin break(FileUtils::cp_r(srcdir, dstdir)) rescue => e raise if attempts > 2 warn{ e } Util::uncache srcdir rescue nil Util::uncache dstdir rescue nil sleep 2 ensure attempts += 1 end end #--}}} end |
#rotate ⇒ Object
–{{{
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rq/rotater.rb', line 12 def rotate #--{{{ set_q rot = Util::realpath @argv.shift rot = if rot if File::directory? rot t = Time::now.strftime('%Y%m%d%H%M%S') File::join(rot, "#{ File.basename @qpath }.#{ t }") else rot end else t = Time::now.strftime('%Y%m%d%H%M%S') "#{ @qpath }.#{ t }" end #rot ||= "#{ @qpath }.#{ Util::timestamp.gsub(/[:\s\.-]/,'_') }.rot" abort "<#{ rot }> exists" if rot and test(?e, rot) debug{ "rotation <#{ rot }>" } FileUtils::mkdir_p(File::dirname(rot)) rescue nil rotq = nil @q.transaction do begin #FileUtils::cp_r @qpath, rot self.cp_r @qpath, rot rotq = JobQueue::new rot, 'logger' => @logger rotq.delete 'pending', 'running', 'holding', 'force' => true @q.delete 'dead', 'finished' rescue FileUtils::rm_rf rot raise end end tgz = File:: "#{ rot }.tgz" #dirname = File::dirname rot if(system("cd #{ File::dirname rot } && tar cvfz #{ File::basename tgz } #{ File::basename rot }/ >/dev/null 2>&1")) FileUtils::rm_rf rot rot = tgz end puts "---" puts "rotation : #{ rot }" #puts '---' #puts "q: #{ rotq.path }" #puts "db: #{ rotq.db.path }" #puts "schema: #{ rotq.db.schema }" #puts "lock: #{ rotq.db.lockfile }" EXIT_SUCCESS #--}}} end |