rq-ruby1.8 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/Gemfile +22 -0
  2. data/Gemfile.lock +22 -0
  3. data/INSTALL +166 -0
  4. data/LICENSE +10 -0
  5. data/Makefile +6 -0
  6. data/README +1183 -0
  7. data/Rakefile +37 -0
  8. data/TODO +24 -0
  9. data/TUTORIAL +230 -0
  10. data/VERSION +1 -0
  11. data/bin/rq +902 -0
  12. data/bin/rqmailer +865 -0
  13. data/example/a.rb +7 -0
  14. data/extconf.rb +198 -0
  15. data/gemspec.rb +40 -0
  16. data/install.rb +210 -0
  17. data/lib/rq.rb +155 -0
  18. data/lib/rq/arrayfields.rb +371 -0
  19. data/lib/rq/backer.rb +31 -0
  20. data/lib/rq/configfile.rb +82 -0
  21. data/lib/rq/configurator.rb +40 -0
  22. data/lib/rq/creator.rb +54 -0
  23. data/lib/rq/cron.rb +144 -0
  24. data/lib/rq/defaultconfig.txt +5 -0
  25. data/lib/rq/deleter.rb +51 -0
  26. data/lib/rq/executor.rb +40 -0
  27. data/lib/rq/feeder.rb +527 -0
  28. data/lib/rq/ioviewer.rb +48 -0
  29. data/lib/rq/job.rb +51 -0
  30. data/lib/rq/jobqueue.rb +947 -0
  31. data/lib/rq/jobrunner.rb +110 -0
  32. data/lib/rq/jobrunnerdaemon.rb +193 -0
  33. data/lib/rq/lister.rb +47 -0
  34. data/lib/rq/locker.rb +43 -0
  35. data/lib/rq/lockfile.rb +564 -0
  36. data/lib/rq/logging.rb +124 -0
  37. data/lib/rq/mainhelper.rb +189 -0
  38. data/lib/rq/orderedautohash.rb +39 -0
  39. data/lib/rq/orderedhash.rb +240 -0
  40. data/lib/rq/qdb.rb +733 -0
  41. data/lib/rq/querier.rb +98 -0
  42. data/lib/rq/rails.rb +80 -0
  43. data/lib/rq/recoverer.rb +28 -0
  44. data/lib/rq/refresher.rb +80 -0
  45. data/lib/rq/relayer.rb +283 -0
  46. data/lib/rq/resource.rb +22 -0
  47. data/lib/rq/resourcemanager.rb +40 -0
  48. data/lib/rq/resubmitter.rb +100 -0
  49. data/lib/rq/rotater.rb +98 -0
  50. data/lib/rq/sleepcycle.rb +46 -0
  51. data/lib/rq/snapshotter.rb +40 -0
  52. data/lib/rq/sqlite.rb +286 -0
  53. data/lib/rq/statuslister.rb +48 -0
  54. data/lib/rq/submitter.rb +113 -0
  55. data/lib/rq/toucher.rb +182 -0
  56. data/lib/rq/updater.rb +94 -0
  57. data/lib/rq/usage.rb +1222 -0
  58. data/lib/rq/util.rb +304 -0
  59. data/rdoc.sh +17 -0
  60. data/rq-ruby1.8.gemspec +120 -0
  61. data/test/.gitignore +1 -0
  62. data/test/test_rq.rb +145 -0
  63. data/white_box/crontab +2 -0
  64. data/white_box/joblist +8 -0
  65. data/white_box/killrq +18 -0
  66. data/white_box/rq_killer +27 -0
  67. metadata +208 -0
@@ -0,0 +1,7 @@
1
+ require 'rq'
2
+
3
+ q = RQ::JobQueue.new 'q'
4
+
5
+ q.submit 'echo 42'
6
+
7
+ y q.list
@@ -0,0 +1,198 @@
1
+ class Main
2
+ $VERBOSE = nil
3
+ #ENV["RUBYOPT"] = "-W0"
4
+
5
+ require "rbconfig"
6
+ require "fileutils"
7
+ include FileUtils
8
+
9
+ begin
10
+ require 'rubygems'
11
+ rescue Object
12
+ nil
13
+ end
14
+
15
+ Makefile = <<-txt
16
+ all:
17
+ \t@ruby -e 42
18
+ clean:
19
+ \t@ruby -e 42
20
+ install:
21
+ \t@ruby -e 42
22
+ txt
23
+
24
+ def initialize
25
+ setup
26
+ gen_makefile
27
+ install_private_posixlock unless installed_posixlock?
28
+ install_private_sqlite unless installed_sqlite?
29
+ install_private_sqlite_ruby unless installed_sqlite_ruby?
30
+ end
31
+
32
+ def setup
33
+ @config = Config::CONFIG
34
+
35
+ @prefix = File.dirname(File.expand_path(__FILE__))
36
+
37
+ Dir.chdir @prefix
38
+ puts "-->> #{ Dir.pwd }"
39
+
40
+ @libdir = File.join @prefix, "lib"
41
+ @alldir = File.join @prefix, "all"
42
+ @srcdir = File.join @alldir, "packages"
43
+
44
+ @rqlibdir = Dir["#{ @libdir }/rq*"].detect{|e| test ?d, e}
45
+
46
+
47
+ @local = File.join @rqlibdir, "local"
48
+ @arch = @config["sitearch"] || @config["arch"]
49
+ @archdir = File.join @rqlibdir, @arch
50
+
51
+ FileUtils.mkdir_p @local
52
+ FileUtils.mkdir_p @archdir
53
+
54
+ @ld_library_path = File.join @local, "lib"
55
+ @ld_run_path = File.join @local, "lib"
56
+
57
+ #ENV["LD_LIBRARY_PATH"] = "" #@ld_library_path
58
+ ENV["LD_RUN_PATH"] = ""
59
+
60
+ @srcs = Dir["#{ @srcdir }/*"]
61
+
62
+ @ruby = File::join(@config['bindir'], @config['ruby_install_name']) << @config['EXEEXT']
63
+ end
64
+
65
+ def gen_makefile
66
+ indent = nil
67
+ open("Makefile", "w") do |f|
68
+ Makefile.each do |line|
69
+ indent ||= line[%r/^\s*/]
70
+ line[%r/^#{ indent }/] = ''
71
+ f.puts line
72
+ end
73
+ end
74
+ end
75
+
76
+ def install_private_posixlock
77
+ tgz = @srcs.detect{|tgz| tgz =~ %r/(posixlock)-(\d+\.\d+\.\d+)\.(tar\.gz|tgz)$/}
78
+ abort "no posixlock" unless tgz
79
+ base, version, ext = $1, $2, $3
80
+ tgz = File.expand_path tgz
81
+ mkdir_p "build"
82
+ Dir.chdir "build" do
83
+ puts "-->> #{ Dir.pwd }"
84
+ cp tgz, "."
85
+ tgz = File.basename tgz
86
+ spawn "gzip -f -d #{ tgz }"
87
+ spawn "tar xf #{ base }-#{ version }*tar"
88
+ Dir.chdir "#{ base }-#{ version }" do
89
+ puts "-->> #{ Dir.pwd }"
90
+ spawn "#{ @ruby } extconf.rb"
91
+ spawn "make clean"
92
+ spawn "make"
93
+ so = Dir["posixlock.{bundle,so}"].first
94
+ chmod 0755, so
95
+ mv so, @archdir
96
+ puts "#{ so } => #{ @archdir }"
97
+ end
98
+ end
99
+ end
100
+
101
+ def installed_posixlock?
102
+ gem_or_pkg_installed?('posixlock')
103
+ end
104
+
105
+ def install_private_sqlite
106
+ tgz = @srcs.detect{|tgz| tgz =~ %r/(sqlite)-(\d+\.\d+\.\d+)\.(tar\.gz|tgz)$/}
107
+ abort "no sqlite" unless tgz
108
+ base, version, ext = $1, $2, $3
109
+ tgz = File.expand_path tgz
110
+ mkdir_p "build"
111
+ Dir.chdir "build" do
112
+ puts "-->> #{ Dir.pwd }"
113
+ cp tgz, "."
114
+ tgz = File.basename tgz
115
+ spawn "gzip -f -d #{ tgz }"
116
+ spawn "tar xf #{ base }-#{ version }*tar"
117
+ Dir.chdir "#{ base }-#{ version }" do
118
+ puts "-->> #{ Dir.pwd }"
119
+ spawn "ls Makefile >/dev/null 2>&1 || ./configure --prefix=#{ @local }"
120
+ spawn "chmod 777 ./libtool"
121
+ spawn "make clean"
122
+ spawn "make"
123
+ spawn "make install"
124
+ end
125
+ end
126
+ end
127
+
128
+ def installed_sqlite?
129
+ program_installed?('sqlite')
130
+ end
131
+
132
+ def install_private_sqlite_ruby
133
+ tgz = @srcs.detect{|tgz| tgz =~ %r/(sqlite-ruby)-(\d+\.\d+\.\d+)\.(tar\.gz|tgz)$/}
134
+ abort "no sqlite-ruby" unless tgz
135
+ base, version, ext = $1, $2, $3
136
+ tgz = File.expand_path tgz
137
+ mkdir_p "build"
138
+ Dir.chdir "build" do
139
+ puts "-->> #{ Dir.pwd }"
140
+ cp tgz, "."
141
+ tgz = File.basename tgz
142
+ spawn "gzip -f -d #{ tgz }"
143
+ spawn "tar xf #{ base }-#{ version }*tar"
144
+ Dir.chdir "#{ base }-#{ version }" do
145
+ puts "-->> #{ Dir.pwd }"
146
+ Dir.chdir "ext" do
147
+ puts "-->> #{ Dir.pwd }"
148
+ spawn "#{ @ruby } extconf.rb --with-sqlite-dir=#{ @local }"
149
+ spawn "make clean"
150
+ spawn "make"
151
+ so = Dir["_sqlite.*"].first
152
+ chmod 0755, so
153
+ mv so, @archdir
154
+ puts "#{ so } => #{ @archdir }"
155
+ end
156
+
157
+ Dir.chdir "lib" do
158
+ Dir["*"].each do |e|
159
+ chmod 0644, e
160
+ mv e, @rqlibdir
161
+ puts "#{ e } => #{ @rqlibdir }"
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ def installed_sqlite_ruby?
169
+ gem_or_pkg_installed?('sqlite')
170
+ end
171
+
172
+ def install_gem gem, opts = ''
173
+ spawn "gem install #{ gem } #{ opts }" unless gem_or_pkg_installed?(gem)
174
+ end
175
+
176
+ def gem_or_pkg_installed? gem
177
+ begin
178
+ require gem
179
+ gem
180
+ rescue
181
+ false
182
+ end
183
+ end
184
+
185
+ def program_installed? basename
186
+ dirname = ENV['PATH'].split(File::PATH_SEPARATOR).detect{|path| test(?x, File.join(path, basename.to_s))}
187
+ dirname ? File.join(dirname, basename) : false
188
+ end
189
+
190
+ def spawn cmd
191
+ puts cmd
192
+ system cmd
193
+ ensure
194
+ abort "cmd <#{ cmd }> failed with <#{ $?.inspect }>" unless $?.exitstatus == 0
195
+ end
196
+ end
197
+
198
+ Main.new
@@ -0,0 +1,40 @@
1
+ #! /usr/bin/env gem build
2
+
3
+ lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
4
+
5
+ require 'rubygems'
6
+
7
+ Gem::Specification::new do |spec|
8
+ $VERBOSE = nil
9
+
10
+ shiteless = lambda do |list|
11
+ list.delete_if do |file|
12
+ file =~ %r/\.svn/ or
13
+ file =~ %r/\.tmp/
14
+ end
15
+ end
16
+
17
+ spec.name = lib
18
+ spec.version = version
19
+ spec.platform = Gem::Platform::RUBY
20
+ spec.summary = lib
21
+
22
+ spec.files = shiteless[Dir::glob("**/**")]
23
+ spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
24
+
25
+ spec.require_path = "lib"
26
+
27
+ spec.has_rdoc = File::exist? "doc"
28
+ spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
29
+
30
+ spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
31
+
32
+ spec.rubyforge_project = 'codeforpeople'
33
+ spec.author = "Ara T. Howard"
34
+ spec.email = "ara.t.howard@gmail.com"
35
+ spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
36
+
37
+ %w( arrayfields lockfile posixlock ).each do |depend|
38
+ spec.add_dependency depend
39
+ end
40
+ end
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env ruby1.8
2
+ require 'rbconfig'
3
+ require 'find'
4
+ require 'ftools'
5
+ require 'tempfile'
6
+ include Config
7
+
8
+ LIBDIR = "lib"
9
+ LIBDIR_MODE = 0644
10
+
11
+ BINDIR = "bin"
12
+ BINDIR_MODE = 0755
13
+
14
+
15
+ $srcdir = CONFIG["srcdir"]
16
+ $version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
17
+ $libdir = File.join(CONFIG["libdir"], "ruby", $version)
18
+ $archdir = File.join($libdir, CONFIG["arch"])
19
+ $site_libdir = $:.find {|x| x =~ /site_ruby$/}
20
+ $bindir = CONFIG["bindir"] || CONFIG['BINDIR']
21
+ $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
22
+ $ruby_ext = CONFIG['EXEEXT'] || ''
23
+ $ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
24
+
25
+ if !$site_libdir
26
+ $site_libdir = File.join($libdir, "site_ruby")
27
+ elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
28
+ $site_libdir = File.join($site_libdir, $version)
29
+ end
30
+
31
+ def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
32
+ #{{{
33
+ path = []
34
+ dir = []
35
+ Find.find(srcdir) do |f|
36
+ next unless FileTest.file?(f)
37
+ next if (f = f[srcdir.length+1..-1]) == nil
38
+ next if (/CVS$/ =~ File.dirname(f))
39
+ next if f =~ %r/\.lnk/
40
+ path.push f
41
+ dir |= [File.dirname(f)]
42
+ end
43
+ for f in dir
44
+ next if f == "."
45
+ next if f == "CVS"
46
+ File::makedirs(File.join(destdir, f))
47
+ end
48
+ for f in path
49
+ next if (/\~$/ =~ f)
50
+ next if (/^\./ =~ File.basename(f))
51
+ unless bin
52
+ File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
53
+ else
54
+ from = File.join(srcdir, f)
55
+ to = File.join(destdir, f)
56
+ shebangify(from) do |sf|
57
+ $deferr.print from, " -> ", File::catname(from, to), "\n"
58
+ $deferr.printf "chmod %04o %s\n", mode, to
59
+ File::install(sf, to, mode, false)
60
+ end
61
+ end
62
+ end
63
+ #}}}
64
+ end
65
+ def shebangify f
66
+ #{{{
67
+ open(f) do |fd|
68
+ buf = fd.read 42
69
+ if buf =~ %r/^\s*#\s*!.*ruby/o
70
+ ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
71
+ begin
72
+ fd.rewind
73
+ ftmp.puts "#!#{ $ruby }"
74
+ while((buf = fd.read(8192)))
75
+ ftmp.write buf
76
+ end
77
+ ftmp.close
78
+ yield ftmp.path
79
+ ensure
80
+ ftmp.close!
81
+ end
82
+ else
83
+ yield f
84
+ end
85
+ end
86
+ #}}}
87
+ end
88
+ def ARGV.switch
89
+ #{{{
90
+ return nil if self.empty?
91
+ arg = self.shift
92
+ return nil if arg == '--'
93
+ if arg =~ /^-(.)(.*)/
94
+ return arg if $1 == '-'
95
+ raise 'unknown switch "-"' if $2.index('-')
96
+ self.unshift "-#{$2}" if $2.size > 0
97
+ "-#{$1}"
98
+ else
99
+ self.unshift arg
100
+ nil
101
+ end
102
+ #}}}
103
+ end
104
+ def ARGV.req_arg
105
+ #{{{
106
+ self.shift || raise('missing argument')
107
+ #}}}
108
+ end
109
+ def linkify d, linked = []
110
+ #--{{{
111
+ if test ?d, d
112
+ versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
113
+ versioned.each do |v|
114
+ src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
115
+ lnk = nil
116
+ begin
117
+ if test ?l, dst
118
+ lnk = "#{ dst }.lnk"
119
+ puts "#{ dst } -> #{ lnk }"
120
+ File::rename dst, lnk
121
+ end
122
+ unless test ?e, dst
123
+ puts "#{ src } -> #{ dst }"
124
+ File::copy src, dst
125
+ linked << dst
126
+ end
127
+ ensure
128
+ if lnk
129
+ at_exit do
130
+ puts "#{ lnk } -> #{ dst }"
131
+ File::rename lnk, dst
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ linked
138
+ #--}}}
139
+ end
140
+
141
+
142
+ #
143
+ # main program
144
+ #
145
+
146
+ libdir = $site_libdir
147
+ bindir = $bindir
148
+ no_linkify = false
149
+ linked = nil
150
+ help = false
151
+
152
+ usage = <<-usage
153
+ #{ File::basename $0 }
154
+ -d, --destdir <destdir>
155
+ -l, --libdir <libdir>
156
+ -b, --bindir <bindir>
157
+ -r, --ruby <ruby>
158
+ -n, --no_linkify
159
+ -s, --sudo
160
+ -h, --help
161
+ usage
162
+
163
+ begin
164
+ while switch = ARGV.switch
165
+ case switch
166
+ when '-d', '--destdir'
167
+ libdir = ARGV.req_arg
168
+ when '-l', '--libdir'
169
+ libdir = ARGV.req_arg
170
+ when '-b', '--bindir'
171
+ bindir = ARGV.req_arg
172
+ when '-r', '--ruby'
173
+ $ruby = ARGV.req_arg
174
+ when '-n', '--no_linkify'
175
+ no_linkify = true
176
+ when '-s', '--sudo'
177
+ sudo = 'sudo'
178
+ when '-h', '--help'
179
+ help = true
180
+ else
181
+ raise "unknown switch #{switch.dump}"
182
+ end
183
+ end
184
+ rescue
185
+ STDERR.puts $!.to_s
186
+ STDERR.puts usage
187
+ exit 1
188
+ end
189
+
190
+ if help
191
+ STDOUT.puts usage
192
+ exit
193
+ end
194
+
195
+ system "#{ sudo } #{ $ruby } pre-install.rb" if test(?s, 'pre-install.rb')
196
+
197
+ unless no_linkify
198
+ linked = linkify('lib') + linkify('bin')
199
+ end
200
+
201
+ system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
202
+
203
+ install_rb(LIBDIR, libdir, LIBDIR_MODE)
204
+ install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
205
+
206
+ if linked
207
+ linked.each{|path| File::rm_f path}
208
+ end
209
+
210
+ system "#{ sudo } #{ $ruby } post-install.rb" if test(?s, 'post-install.rb')