Class: RQ::Locker

Inherits:
MainHelper show all
Defined in:
lib/rq/locker.rb

Overview

a Locker simply obtains an exclusive lock on a queue’s lock and then runs and arbitrary command which is taken from the command line only. it’s use is simply to allow unforseen applications to coordinate access to the queue

Constant Summary

Constants included from Logging

RQ::Logging::DIV0, RQ::Logging::DIV1, RQ::Logging::DIV2, RQ::Logging::DIV3, RQ::Logging::EOL, RQ::Logging::SEC0, RQ::Logging::SEC1, RQ::Logging::SEC2, RQ::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

Methods inherited from MainHelper

#dumping_yaml_tuples, #field_match, #init_job_stdin!, #initialize, #loadio, #loadyaml, #set_q

Methods included from Logging

append_features

Methods included from RQ::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

#lockObject

–{{{



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rq/locker.rb', line 18

def lock
#--{{{
  set_q
  ltype = @argv.shift
  debug{ "ltype <#{ ltype }>" }
  read_only =
    case ltype
      when /^\s*r(?:ead)?|^\s*sh(?:ared)?/io
        true
      when /^\s*w(?:rite)?|^\s*ex(?:clusive)?/io
        false
      else
        raise "lock type must be one of (r)ead|(sh)ared|(w)rite|(ex)clusive, not <#{ ltype }>"
    end
  cmd = @argv.join(' ').strip
  raise "no command given for lock type <#{ ltype }>" if cmd.empty?
  debug{ "cmd <#{ cmd }>" }
  @q.lock(:read_only => read_only){ Util::system cmd }
#--}}}
end