beaneater 1.1.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27dbb64059340085f2e89899e550b2329db2043e96491ae2561b2dd4f2bb34ea
4
- data.tar.gz: 3bf0277effe249cbbcd95e6643c6d5f7c8bd7a3efeee3a3e86f2cd6c53b59402
3
+ metadata.gz: 9f50f38f9e485e31b15278b6fdff9a8d74e13aa6fc3e0c9f0c366b5091f5b2d5
4
+ data.tar.gz: b16e2755db5a25f216a1b4577b925536edebfd304c5e497ea8189dbb8630cf6e
5
5
  SHA512:
6
- metadata.gz: 65c0e86ba162862f43ec6bf3d4c0f45b1e30821f7bd7a891d8833be1312d256d2ec6999406bee08c5bf0e151ce2a599a7274c9179f3b64563d6168fc02f39888
7
- data.tar.gz: ab0f650fade61572fb3b1a8c57c3e0c15634e826f1a5cd2635ef07e4270ce472f8b53c02488028b14c25a294498b3b494854d3f52e798109a61ef7cb957bc674
6
+ metadata.gz: 07c0c6c6032c57630e23515ab53549379de75ba2e985449ac849003e57f5317663dda129aa1bb89f8b61e1fa535c7f385373a009e79043cd6cfb9cd00e3c7ac9
7
+ data.tar.gz: 04c2851609baa2d9b73057ad45567093bba58e1689ee418f967c547388be683193fa01a73a18a4b2e8401c632a6f0a49cceeaa56c352db8540e89aba764fd438
@@ -22,14 +22,16 @@ jobs:
22
22
  runs-on: ubuntu-latest
23
23
  strategy:
24
24
  matrix:
25
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
25
+ ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0']
26
26
 
27
27
  steps:
28
- - uses: actions/checkout@v3
28
+ - uses: actions/checkout@v4
29
29
  - name: Download & Extract beanstalkd
30
30
  run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
31
31
  - name: Make beanstalkd
32
- run: make
32
+ # beanstalkd 1.13 builds with -Werror and predates C23, which newer compilers default to: build it
33
+ # as C17, and keep the const pointer newer C libraries' memchr() returns to prot.c a warning
34
+ run: make CFLAGS='-std=gnu17 -Wno-error=discarded-qualifiers'
33
35
  working-directory: beanstalkd-1.13
34
36
  - name: Set up Ruby
35
37
  uses: ruby/setup-ruby@v1
@@ -40,3 +42,5 @@ jobs:
40
42
  run: ./beanstalkd-1.13/beanstalkd &
41
43
  - name: Run tests
42
44
  run: bundle exec rake test:full
45
+ env:
46
+ BEANSTALKD_BIN: ${{ github.workspace }}/beanstalkd-1.13/beanstalkd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # CHANGELOG for Beaneater
2
2
 
3
+ ## 1.3.0 (November 1 2026)
4
+
5
+ * Check tube names, job ids and numbers before writing them into a command. A tube name beanstalkd does not accept (up to 200 letters, digits and `-+/;.$_()`, not starting with a hyphen) raises `InvalidTubeName` from every tube command (`use`, `watch`, `ignore`, `put`, `peek`, `kick`, `stats`, `pause`, and restoring the watched tubes on reconnect); names such as `demo.test.foo`, `jobs(eu).mailers` and `MyApp.mailers` stay valid. `watch`'s `InvalidTubeName` message now reads "Tube cannot be named '<name>'", as `use`'s does, and `tubes.watch(:t)` and `tubes.ignore(:t)` return the names as Strings. A job id that is not a whole number (an Integer or a String of digits), a priority, delay, TTR or pause delay that is not a whole number from 0 to 4294967295 (the range beanstalkd reads), a reserve timeout or kick count that is neither a whole number nor a Float, and a peek state other than `ready`, `delayed` or `buried` raise `ArgumentError`. Such values used to be sent as given and fail on the server with `BadFormatError` or `UnknownCommandError`, or be misread. What to do: `tube.stats`, `tube.pause` and `tubes.ignore` with such a tube name now raise `InvalidTubeName` instead of `BadFormatError`, and the values above raise `ArgumentError` (`jobs.find("abc")`, `tube.put(body, :ttr => 1.5)`, `tube.peek(:reserved)`) instead of `BadFormatError` or `UnknownCommandError`, both `Beaneater::UnexpectedResponse`s; code that rescues `Beaneater::UnexpectedResponse` around these calls should also rescue `Beaneater::InvalidTubeName` and `ArgumentError` (@nesquena)
6
+ * `stats[key]` (on `client.stats`, `job.stats` and `tube.stats`) reads the stat named by key; a key that is not a stat returns nil (keys that are also method names, such as `"hash"` or `"send"`, used to return something else or raise `ArgumentError`). Readers such as `stats.current_jobs_ready` and hyphenated keys such as `stats['current-jobs-ready']` work as before (@nesquena)
7
+ * Development only: require redcarpet 3.6 for the YARD docs task (`rake yard`), which failed with redcarpet 1.x (`undefined method 'lax_spacing=' for RedcarpetCompat`); this also clears the Dependabot alert on redcarpet 1.x. The gem itself has no new dependency (@nesquena)
8
+ * Set the gem's homepage (it was empty) and add `changelog_uri`, `source_code_uri` and `bug_tracker_uri` to its metadata, so rubygems.org links to the repository, this changelog and the issues; set `rubygems_mfa_required`, so pushing a release to rubygems.org now requires MFA; remove the unused `.travis.yml` (@nesquena)
9
+ * `NotConnected` for an address beaneater can't parse (`[::1]:11300`, `::1`, `beanstalk://host:11300`) names the address as given, leaving out any `user:password@`; the message read "Connection to beanstalk ':' is closed!". IPv6 addresses and URLs are still not supported (@nesquena)
10
+ * `jobs.process!` with no processor registered raises `ArgumentError` ("no processors registered: call jobs.register(tube_name) { |job| ... } first") instead of `NoMethodError: undefined method 'keys' for nil`; it sends nothing to the server (@nesquena)
11
+ * `respond_to?` on `client.stats` and on a `StatStruct` (`job.stats`, `tube.stats`) answers true for every stats key, also before the key is first read (it was false until then), so `respond_to?` and `method(:key)` agree with the readers. `client.stats.respond_to?` asks the server for the keys, as reading a stat does (@nesquena)
12
+ * The connection remembers each watched tube once and by name, so a reconnect no longer re-sends `watch` for every repeated `tubes.watch(name)`, and `tubes.ignore(:name)` forgets a tube watched as `"name"` (and the other way round); `connection.tubes_watched` holds only strings (@nesquena)
13
+ * `Job#release` and `Job#bury` no longer send `stats-job` for a `:pri` or `:delay` the caller gave: `release(:pri => p, :delay => d)` and `bury(:pri => p)` now take no extra round trip (they took 2 and 1), and `release` with either one missing takes one (it took 2) (@nesquena)
14
+
15
+ ## 1.2.0 (October 31 2026)
16
+
17
+ * `Jobs#process!` buries a job whose body the `job_parser` rejects (`JSON.parse` on a non-JSON job, say); it used to stay reserved until its TTR ran out and then fail again, for ever. A parser that raises `AbortProcessingError` has its job buried and stops the loop, as a handler's abort does. The job is not buried when the parser raises `NotConnected` while this client's connection is gone (`process!` raises it, and beanstalkd releases the job), an exception that isn't a `StandardError` (`process!` raises it, and the job stays reserved until its TTR runs out or the connection closes), or one that can't be copied (raised untagged, so `process!` can't tell which job it came from: the job stays reserved and `process!` keeps failing on it; make parser exceptions copyable). A plain `tubes.reserve` raises a copy of the parser's error with the same class, message, cause and backtrace (a frozen exception, for which Ruby records no backtrace, gets one that starts in beaneater), so `rescue JSON::ParserError` keeps working; the copy is also a `Beaneater::JobParseFailure`, whose `#job_id` names the job, still reserved by the connection (@nesquena)
18
+ * `close` while a command is waiting on the connection (a `reserve`, say), whether from a signal handler or from another thread, now makes that command raise `NotConnected`; 1.1.x raised `IOError`, and on Ruby 3.3 and 3.4 a `close` from a signal handler could crash the process. A `close` from a `job_parser` lets its command finish, then closes the socket (@nesquena)
19
+ * Drop the connection when a command is interrupted mid-reply (for example by `Timeout.timeout`), so the next command no longer reads the stale reply (reported by @tdegrunt)
20
+ * Honour `stop!` while `process!` is waiting for a job with `reserve_timeout` set (reported by @martint17r)
21
+ * Keep `process!` running when a handler deletes or releases its job, or overruns its TTR, and then raises; it used to stop with `NotFoundError` or `JobNotReserved`. A handler that raises one of those (or `TimedOutError`) while its job is still reserved now has the job buried like any other failure, instead of leaving it reserved and forgotten, which made `process!` reserve in a tight loop of `DEADLINE_SOON` replies near the job's TTR. To have such a job released for another try instead, add the error to the handler's `retry_on` (`jobs.register(tube, :retry_on => [Beaneater::NotFoundError])`); it is released up to `max_retries` times, then buried (reported by @pagojo)
22
+ * Reconnect on the next command after the connection was lost, restoring the used and watched tubes (while beanstalkd is down each command now retries for about 2 seconds before raising `NotConnected`, and gives up after 3 reconnects when every new connection is dropped at once; set `connect_timeout` in web apps that enqueue during requests), and make `process!` raise `NotConnected` instead of looping while its beanstalkd is down (a handler that raises `NotConnected` for another server still has its job buried, as before) (reported by @b-sridhar and @Meekohi)
23
+ * Test on Ruby 2.7 to 3.4 and 4.0 in CI (dropping 2.6), and update `actions/checkout` to v4 (@nesquena)
24
+ * Require Ruby 2.7 or newer, declared in the gemspec, so older Rubies get a clear install-time error instead of failing at runtime (the code needs at least 2.5 for `Hash#slice`), #83 (@nesquena; reported by @hkmaly)
25
+ * Make `read_timeout` and `write_timeout` take effect: they set `SO_RCVTIMEO`/`SO_SNDTIMEO`, which have no effect on Ruby 3 (Ruby waits on the socket itself), so a server that stopped answering still blocked forever. Beaneater now enforces both itself, adds `read_timeout` to `reserve(timeout)`'s own wait, never cuts off a plain `reserve`, and on timeout raises the new `Beaneater::SocketTimeout` (a `NotConnected`) and drops the connection, so the next command reconnects. `read_timeout` and `write_timeout` may be numeric strings. A `SocketTimeout` on `put` is ambiguous (beanstalkd may have stored the job), so retrying it can enqueue the job twice (@nesquena)
26
+ * Fix a raising `job_parser` (e.g. `JSON.parse` on a non-JSON job) leaving the connection one reply out of step, so later commands returned the wrong replies (@nesquena)
27
+ * Fix stats and tube lists mangling values since 1.1.2: `-`, `:` and `~` were rewritten to `_`, so `job.tube` for tube `email-jobs` was `"email_jobs"` and `Jobs#process!` buried its jobs; tube names that look like dates or numbers (`2026-10-30`, `1.10`) are now returned as strings instead of raising or being converted (@nesquena)
28
+ * Add `connect_timeout` (Ruby 3+), `resolv_timeout` (Ruby 3+), `read_timeout`, and `write_timeout` configuration options (@rveznaver)
29
+ * Fix `StatStruct#[]` raising a `SyntaxError` when looking up hyphenated beanstalkd keys (e.g. `stats['current-jobs-ready']`); keys are now underscored before lookup to match how they are stored (@dkam)
30
+
3
31
  ## 1.1.4 (March 6 2026)
4
32
 
5
33
  * Add frozen string literal comments for Ruby 3.4 compatibility (@nearapogee)
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  group :development do
9
- gem 'redcarpet', '~> 1'
9
+ gem 'redcarpet', '~> 3.6'
10
10
  gem 'github-markup'
11
11
  gem 'yard'
12
12
  end
data/README.md CHANGED
@@ -133,11 +133,21 @@ Beaneater.configure do |config|
133
133
  # config.job_parser = lambda { |body| body }
134
134
  # config.job_serializer = lambda { |body| body }
135
135
  # config.beanstalkd_url = 'localhost:11300'
136
+ # config.connect_timeout = nil
137
+ # config.resolv_timeout = nil
138
+ # config.read_timeout = nil
139
+ # config.write_timeout = nil
136
140
  end
137
141
  ```
138
142
 
139
143
  The above options are all defaults, so only include a configuration block if you need to make changes.
140
144
 
145
+ `connect_timeout` and `resolv_timeout` are passed through to `TCPSocket.new` on Ruby 3.0 and newer (ignored on Ruby < 3.0 for compatibility). `read_timeout` bounds how long beaneater waits for beanstalkd's reply to a command; for `reserve(timeout)` it is added to the reserve's own timeout, and a plain `reserve` (no timeout) still waits as long as it takes for a job. `write_timeout` bounds how long sending a command may take. When either runs out, `Beaneater::SocketTimeout` (a `Beaneater::NotConnected`) is raised and the connection is dropped; the next command reconnects. Timeouts are in seconds; `read_timeout` and `write_timeout` may also be numeric strings (from `ENV`, say).
146
+
147
+ A `SocketTimeout` on `put` does not tell you whether beanstalkd stored the job: the command may have reached the server and only the reply been lost. Retrying the `put` can therefore enqueue the job twice, so retry a timed-out `put` only if running the job twice is harmless.
148
+
149
+ While beanstalkd is unreachable, every command tries to reconnect three times, one second apart, before raising `Beaneater::NotConnected`, so each command takes about 2 seconds to fail (longer per attempt when connecting itself hangs, as with an unreachable host). Threads sharing a client pause between their retries side by side, but the connection attempts themselves still run one at a time. Apps that enqueue jobs inside web requests should set `connect_timeout` and expect this delay while beanstalkd is down.
150
+
141
151
  ### Connection
142
152
 
143
153
  To interact with a beanstalk queue, first establish a connection by providing an address:
@@ -412,6 +422,23 @@ The `process!` command is ideally suited for a beanstalk job processing daemon.
412
422
  Even though `process!` is intended to be a long-running process, you can stop the loop at any time
413
423
  by raising `AbortProcessingError` while processing is running.
414
424
 
425
+ If the `job_parser` raises for a job (a body that isn't JSON, say), `process!` buries that job and
426
+ goes on; if it raises `AbortProcessingError`, `process!` buries the job and stops, as for a
427
+ handler's abort. The job is not buried when the parser raises `NotConnected` while this client's
428
+ connection is gone (`process!` raises it, and beanstalkd releases the job), an exception that isn't
429
+ a `StandardError` (`process!` raises it, and the job stays reserved until its TTR runs out or the
430
+ connection closes), or one that can't be copied (raised untagged, so `process!` can't tell which job
431
+ it came from: the job stays reserved and `process!` keeps failing on it; make parser exceptions
432
+ copyable). A direct `tubes.reserve` raises a copy of
433
+ the parser's error (same class, message, cause and backtrace; a frozen exception, for which Ruby
434
+ records no backtrace, gets one that starts in beaneater) that is also a
435
+ `Beaneater::JobParseFailure`: its `job_id` names the job, still reserved by your connection, so
436
+ you can bury, release or delete it.
437
+
438
+ If beanstalkd goes away and reconnecting fails, `process!` raises `Beaneater::NotConnected`.
439
+ The client reconnects on its next command, so calling `process!` again (for example from a
440
+ supervisor loop) resumes once the server is back.
441
+
415
442
  ### Handling Errors
416
443
 
417
444
  While using Beaneater, certain errors may be encountered. Errors are encountered when
@@ -421,11 +448,17 @@ are listed below:
421
448
  | Errors | Description |
422
449
  | -------------------- | ------------- |
423
450
  | Beaneater::NotConnected | Client connection to beanstalk cannot be established. |
424
- | Beaneater::InvalidTubeName | Specified tube name for use or watch is not valid. |
451
+ | Beaneater::InvalidTubeName | Specified tube name is not valid: beanstalkd takes up to 200 letters, digits and `-+/;.$_()`, not starting with a hyphen. |
425
452
  | Beaneater::NotFoundError | Specified job or tube could not be found. |
426
453
  | Beaneater::TimedOutError | Job could not be reserved within time specified. |
454
+ | Beaneater::SocketTimeout | No reply within `read_timeout` (or the write exceeded `write_timeout`); the connection is dropped and the next command reconnects. A subclass of `NotConnected`, not to be confused with `TimedOutError`. |
427
455
  | Beaneater::JobNotReserved | Job has not been reserved and action cannot be taken. |
428
456
 
457
+ A job id that is not a whole number (an Integer or a String of digits), a priority, delay, TTR or
458
+ pause delay that is not a whole number from 0 to 4294967295, a reserve timeout or kick count that is
459
+ neither a whole number nor a Float, and a peek state other than `ready`, `delayed` or `buried` raise
460
+ `ArgumentError` before anything is sent.
461
+
429
462
  There are other exceptions that are less common such as `OutOfMemoryError`, `DrainingError`,
430
463
  `DeadlineSoonError`, `InternalError`, `BadFormatError`, `UnknownCommandError`,
431
464
  `ExpectedCRLFError`, `JobTooBigError`, `NotIgnoredError`. Be sure to check the
data/Rakefile CHANGED
@@ -4,6 +4,9 @@ require "bundler/gem_tasks"
4
4
  require 'rake/testtask'
5
5
  require 'yard'
6
6
  require 'redcarpet'
7
+ require 'json'
8
+ require 'net/http'
9
+ require_relative 'lib/beaneater/version'
7
10
 
8
11
  # rake test
9
12
  Rake::TestTask.new do |t|
@@ -32,4 +35,56 @@ YARD::Rake::YardocTask.new do |t|
32
35
  t.options = []
33
36
  end
34
37
 
38
+ # rake release:check (rake release runs it first, before it builds, tags or pushes):
39
+ # HEAD must be on master (or X.Y-stable), committed and at the remote branch it will be
40
+ # pushed to (`origin` unless `rake release[remote]` or the branch's upstream says
41
+ # otherwise), version.rb must match the top CHANGELOG.md heading, stamped with a date,
42
+ # and neither the tag nor the gem version may exist yet.
43
+ desc "Check that HEAD can be released as beaneater #{Beaneater::VERSION}"
44
+ task "release:check", [:remote] do |_, args|
45
+ version = Beaneater::VERSION
46
+ tag = "v#{version}"
47
+ git = ->(*a) { out = IO.popen(["git", *a], err: File::NULL, &:read); out.strip if $?.success? }
48
+ errors = []
49
+
50
+ branch = git.("rev-parse", "--abbrev-ref", "HEAD").to_s
51
+ remote = args[:remote] || git.("config", "--get", "branch.#{branch}.remote") || "origin"
52
+ errors << "git fetch #{remote} failed" unless system("git", "fetch", "--quiet", remote)
53
+ stable = "#{version[/\A\d+\.\d+/]}-stable"
54
+ errors << "on #{branch}, not master or #{stable}" unless ["master", stable].include?(branch)
55
+ errors << "there are uncommitted changes" unless git.("status", "--porcelain") == ""
56
+ head = git.("rev-parse", "HEAD")
57
+ unless head && head == git.("rev-parse", "--verify", "--quiet", "refs/remotes/#{remote}/#{branch}")
58
+ errors << "#{branch} is not at #{remote}/#{branch} (push or pull first; release a merged commit)"
59
+ end
60
+
61
+ heading = File.foreach(File.expand_path('CHANGELOG.md', __dir__), encoding: "bom|utf-8").find { |l| l.start_with?("## ") }.to_s.strip
62
+ top, rest = heading.match(/\A## (\d+\.\d+\.\d+)( .*|)\z/)&.captures
63
+ if top != version
64
+ errors << "CHANGELOG.md starts with '#{heading}', not #{version}"
65
+ elsif rest !~ /\b(19|20)\d\d\b/ || rest =~ /\b(unreleased|tbd|tba)\b/i
66
+ errors << "CHANGELOG.md's '#{heading}' isn't stamped with a date"
67
+ end
68
+
69
+ local_tag = git.("tag", "--list", tag)
70
+ remote_tag = git.("ls-remote", "--tags", remote, "refs/tags/#{tag}")
71
+ if local_tag.nil? || remote_tag.nil?
72
+ errors << "couldn't check for tag #{tag}"
73
+ elsif !(local_tag.empty? && remote_tag.empty?)
74
+ errors << "tag #{tag} already exists (if only the gem push failed: gem push pkg/beaneater-#{version}.gem)"
75
+ end
76
+
77
+ begin
78
+ published = JSON.parse(Net::HTTP.get(URI("https://rubygems.org/api/v1/versions/beaneater.json")))
79
+ errors << "beaneater #{version} is already on rubygems.org" if published.any? { |v| v["number"] == version }
80
+ rescue StandardError => e
81
+ errors << "couldn't check rubygems.org (#{e.message})"
82
+ end
83
+
84
+ abort "Not ready to release #{version}:\n#{errors.map { |e| " - #{e}" }.join("\n")}" unless errors.empty?
85
+ puts "Ready to release beaneater #{version} (#{git.("rev-parse", "--short", "HEAD")} on #{branch}, #{remote})"
86
+ end
87
+ Rake::Task["release"].prerequisites.unshift("release:check")
88
+ %w[release:source_control_push release:rubygem_push].each { |t| Rake::Task[t].enhance(["release:check"]) }
89
+
35
90
  task :default => 'test:full'
data/beaneater.gemspec CHANGED
@@ -11,13 +11,20 @@ Gem::Specification.new do |gem|
11
11
  gem.email = ["nico.taing@gmail.com"]
12
12
  gem.description = %q{Simple beanstalkd client for ruby}
13
13
  gem.summary = %q{Simple beanstalkd client for ruby.}
14
- gem.homepage = ""
14
+ gem.homepage = "https://github.com/beanstalkd/beaneater"
15
15
  gem.license = 'MIT'
16
+ gem.metadata = {
17
+ "changelog_uri" => "https://github.com/beanstalkd/beaneater/blob/master/CHANGELOG.md",
18
+ "source_code_uri" => "https://github.com/beanstalkd/beaneater",
19
+ "bug_tracker_uri" => "https://github.com/beanstalkd/beaneater/issues",
20
+ "rubygems_mfa_required" => "true"
21
+ }
16
22
 
17
23
  gem.files = `git ls-files`.split($/)
18
24
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
25
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
26
  gem.require_paths = ["lib"]
27
+ gem.required_ruby_version = '>= 2.7'
21
28
  gem.add_development_dependency 'minitest', "~> 4.1.0"
22
29
  gem.add_development_dependency 'rake'
23
30
  gem.add_development_dependency 'mocha'
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Beaneater
4
+ # Checks the values beaneater writes into a command line, so that each one stays a single
5
+ # argument of the form beanstalkd accepts.
6
+ #
7
+ # @private
8
+ module Arguments
9
+ # beanstalkd's tube names: 1 to 200 of these characters, not starting with a hyphen
10
+ TUBE_NAME = %r{\A[A-Za-z0-9+/;.$_()][A-Za-z0-9\-+/;.$_()]{0,199}\z}
11
+ # A whole number, as an Integer or a String of digits
12
+ INTEGER = /\A-?\d+\z/
13
+ # One that isn't negative
14
+ UNSIGNED = /\A\d+\z/
15
+ # The largest priority, delay or TTR beanstalkd reads (a 32-bit unsigned number)
16
+ UINT32_MAX = 4_294_967_295
17
+ # The job states a tube can be peeked at
18
+ PEEK_STATES = %w(ready delayed buried).freeze
19
+
20
+ module_function
21
+
22
+ # @return [String] the tube name
23
+ # @raise [Beaneater::InvalidTubeName] name isn't a tube name beanstalkd accepts
24
+ def tube_name(name)
25
+ name = name.to_s
26
+ raise InvalidTubeName, "Tube cannot be named '#{name}'" unless name.valid_encoding? && name.match?(TUBE_NAME)
27
+ name
28
+ end
29
+
30
+ # @return [Integer, String] value, an Integer or a String of digits (a job id, a priority, a delay)
31
+ # @raise [ArgumentError] value is anything else
32
+ def integer(value, what)
33
+ return value if integer?(value)
34
+ raise ArgumentError, "#{what} must be an integer, not #{value.inspect}"
35
+ end
36
+
37
+ # Like {.integer}, for values beanstalkd takes only as a whole number from 0 to {UINT32_MAX} (a
38
+ # priority, a delay, a TTR): any other would fail on the server, and for put only after its body is sent.
39
+ # @return [Integer, String] value
40
+ # @raise [ArgumentError] value is anything else
41
+ def unsigned(value, what)
42
+ number = value.is_a?(String) && value.match?(UNSIGNED) ? Integer(value, 10) : value
43
+ return value if number.is_a?(Integer) && number >= 0 && number <= UINT32_MAX
44
+ raise ArgumentError, "#{what} must be a whole number from 0 to #{UINT32_MAX}, not #{value.inspect}"
45
+ end
46
+
47
+ # Like {.integer}, also accepting a Float, which beanstalkd reads up to the decimal point
48
+ # where a command allows it (a reserve timeout, the number of jobs to kick).
49
+ def number(value, what)
50
+ return value if value.is_a?(Float) || integer?(value)
51
+ raise ArgumentError, "#{what} must be a number, not #{value.inspect}"
52
+ end
53
+
54
+ def integer?(value)
55
+ value.is_a?(Integer) || (value.is_a?(String) && value.match?(INTEGER))
56
+ end
57
+
58
+ # @return [String] the job state to peek at
59
+ # @raise [ArgumentError] state isn't ready, delayed or buried
60
+ def peek_state(state)
61
+ state = state.to_s
62
+ return state if PEEK_STATES.include?(state)
63
+ raise ArgumentError, "state must be one of #{PEEK_STATES.join(', ')}, not #{state.inspect}"
64
+ end
65
+ end # Arguments
66
+ end # Beaneater
@@ -8,6 +8,10 @@ class Beaneater
8
8
  attr_accessor :job_parser # default job_parser to parse job body
9
9
  attr_accessor :job_serializer # default serializer for job body
10
10
  attr_accessor :beanstalkd_url # default beanstalkd url
11
+ attr_accessor :connect_timeout # TCP connect timeout in seconds
12
+ attr_accessor :resolv_timeout # DNS resolve timeout in seconds
13
+ attr_accessor :read_timeout # seconds to wait for a reply (added to reserve-with-timeout's own timeout; plain reserve is never cut off)
14
+ attr_accessor :write_timeout # seconds to wait for a command to be written
11
15
 
12
16
  def initialize
13
17
  @default_put_delay = 0
@@ -16,6 +20,10 @@ class Beaneater
16
20
  @job_parser = lambda { |body| body }
17
21
  @job_serializer = lambda { |body| body }
18
22
  @beanstalkd_url = nil
23
+ @connect_timeout = nil
24
+ @resolv_timeout = nil
25
+ @read_timeout = nil
26
+ @write_timeout = nil
19
27
  end
20
28
  end # Configuration
21
29
  end # Beaneater