box-office 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +12 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/box-office.gemspec +35 -0
- data/lib/box/office.rb +31 -0
- data/lib/box/office/booth.rb +39 -0
- data/lib/box/office/configuration.rb +85 -0
- data/lib/box/office/connection.rb +37 -0
- data/lib/box/office/janitor.rb +28 -0
- data/lib/box/office/queue.rb +43 -0
- data/lib/box/office/showing.rb +88 -0
- data/lib/box/office/version.rb +7 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc1e432c18b1eadb7ef991820265cfb8932291ad1c876df5099e47accb796a29
|
4
|
+
data.tar.gz: 4f9f0bd0024ca3ba404853443dc320f65820bdbe0e19d60ac6045002e155ed66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac5ce90044ec865ab6e272a64f07e2f1bd21a18ff3b7194647a2ef0aaf2c3230ea8f3b9e9470226b8ad84fe0d55b228adb0660398c368237d8bcde75241d1e78
|
7
|
+
data.tar.gz: eefb458087ce0aeabd5c0702dc433765fdf1fe727ca06a4df8571b7d0ceb8b8475546f90160cb88fb13ee6b60a2fe92d74ab99d6d7c3e56fb94f921d3d4ebeda
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dvmonroe6@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Drew Monroe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Box::Office
|
2
|
+
|
3
|
+
A queue worth lining up for.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'box-office'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install box-office
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
# showing = Box::Office.showing(name: "Jurassic Park", showings: 5)
|
25
|
+
|
26
|
+
# showing.standby.push %w(1 2 3)
|
27
|
+
# showing << %w(1 2 3)
|
28
|
+
# showing.reserve do |queue, members|
|
29
|
+
# p queue
|
30
|
+
# p members
|
31
|
+
# end
|
32
|
+
|
33
|
+
# showing.reserved(1)
|
34
|
+
```
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/box-office. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
## Code of Conduct
|
51
|
+
|
52
|
+
Everyone interacting in the Box::Office project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/box-office/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/box-office.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "box/office/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "box-office"
|
9
|
+
spec.version = Box::Office::VERSION
|
10
|
+
spec.authors = ["Drew Monroe"]
|
11
|
+
spec.email = ["dvmonroe6@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Reliable redis queueing"
|
14
|
+
spec.homepage = "http://github.com/dvmonroe/box-office"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r(^exe/)) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "activesupport", "~> 5.2"
|
25
|
+
spec.add_dependency "redis", "~> 4.1"
|
26
|
+
spec.add_dependency "redlock", "~> 1.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "minitest-reporters", ">= 1.3"
|
31
|
+
spec.add_development_dependency "mocha"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rubocop", "~> 0.61.0"
|
35
|
+
end
|
data/lib/box/office.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/inflector"
|
4
|
+
require "redis"
|
5
|
+
require "redlock"
|
6
|
+
|
7
|
+
require "box/office/version"
|
8
|
+
require "box/office/configuration"
|
9
|
+
|
10
|
+
require "box/office/connection"
|
11
|
+
|
12
|
+
require "box/office/janitor"
|
13
|
+
require "box/office/booth"
|
14
|
+
require "box/office/queue"
|
15
|
+
require "box/office/showing"
|
16
|
+
|
17
|
+
module Box
|
18
|
+
module Office
|
19
|
+
class NoOpenings < StandardError; end
|
20
|
+
class QueueInUse < StandardError; end
|
21
|
+
class NotBoolean < StandardError; end
|
22
|
+
class OutOfRange < StandardError; end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def showing(name: config.default_name, track_fulfilled: config.track_fulfilled,
|
26
|
+
showings: config.showings, capacity: config.capacity)
|
27
|
+
Showing.new(name: name, track_fulfilled: track_fulfilled, showings: showings, capacity: capacity)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Box
|
4
|
+
module Office
|
5
|
+
class Booth
|
6
|
+
include Box::Office::Connection
|
7
|
+
attr_reader :showing
|
8
|
+
|
9
|
+
delegate :config, to: Box::Office
|
10
|
+
|
11
|
+
def initialize(showing:)
|
12
|
+
@showing = showing
|
13
|
+
end
|
14
|
+
|
15
|
+
def first_available_opening(conn)
|
16
|
+
1.upto(showing.showings) do |idx|
|
17
|
+
queue = find_queue(idx)
|
18
|
+
|
19
|
+
Redlock::Client.new([conn]).lock("#{queue.name}-locked", 3000) do |locked|
|
20
|
+
if locked && !Janitor.locked?(queue.name) && queue.length < showing.capacity
|
21
|
+
yield queue
|
22
|
+
return
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
next if idx < showing.showings
|
27
|
+
|
28
|
+
raise NoOpenings, "No available openings for #{showing.name}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def find_queue(idx)
|
35
|
+
showing.send(config.reserved, idx)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Box
|
4
|
+
module Office
|
5
|
+
class Configuration
|
6
|
+
# Redis instance
|
7
|
+
# @return [Object]
|
8
|
+
attr_accessor :instance
|
9
|
+
|
10
|
+
attr_accessor :pool_size
|
11
|
+
|
12
|
+
attr_accessor :standby
|
13
|
+
|
14
|
+
attr_accessor :reserved
|
15
|
+
|
16
|
+
attr_accessor :fulfilled
|
17
|
+
|
18
|
+
attr_accessor :showings
|
19
|
+
|
20
|
+
attr_accessor :default_name
|
21
|
+
|
22
|
+
attr_accessor :track_fulfilled
|
23
|
+
|
24
|
+
attr_accessor :capacity
|
25
|
+
|
26
|
+
attr_accessor :lock_reserved
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@instance = Redis.current
|
30
|
+
@pool_size = 5
|
31
|
+
|
32
|
+
@standby = :standby
|
33
|
+
@reserved = :reserved
|
34
|
+
@fulfilled = :fulfilled
|
35
|
+
@showings = 1
|
36
|
+
@track_fulfilled = true
|
37
|
+
@capacity = 100
|
38
|
+
@default_name = "Box Office Hit"
|
39
|
+
@lock_reserved = true
|
40
|
+
end
|
41
|
+
|
42
|
+
instance_methods.each do |meth|
|
43
|
+
define_method("#{meth}?") do
|
44
|
+
return send(meth) == true if !!send(meth) == send(meth) # rubocop:disable Style/DoubleNegation
|
45
|
+
|
46
|
+
raise NotBoolean, "Configuration##{meth} does not return a Boolean and therefore, has no predicate method."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def single_queues
|
51
|
+
queues - [reserved]
|
52
|
+
end
|
53
|
+
|
54
|
+
def queues
|
55
|
+
[standby, reserved, fulfilled]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Box::Office::Configuration] Box::Office's current configuration
|
60
|
+
def self.configuration
|
61
|
+
@configuration ||= Configuration.new
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
alias config configuration
|
66
|
+
end
|
67
|
+
|
68
|
+
# Set Box::Office's configuration
|
69
|
+
# @param config [Box::Office::Configuration]
|
70
|
+
def self.configuration=(config)
|
71
|
+
@configuration = config
|
72
|
+
end
|
73
|
+
|
74
|
+
# Modify Box::Office's current configuration
|
75
|
+
# @yieldparam [Box::Office] config current Box::Office config
|
76
|
+
# ```
|
77
|
+
# Box::Office.configure do |config|
|
78
|
+
# config.routes = false
|
79
|
+
# end
|
80
|
+
# ```
|
81
|
+
def self.configure
|
82
|
+
yield configuration
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Box
|
6
|
+
module Office
|
7
|
+
module Connection
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def with_connection
|
11
|
+
if defined?(ConnectionPool)
|
12
|
+
if configured_instance.is_a?(ConnectionPool)
|
13
|
+
configured_instance.with { |conn| yield conn }
|
14
|
+
else
|
15
|
+
connection_pool.with { |conn| yield conn }
|
16
|
+
end
|
17
|
+
else
|
18
|
+
yield configured_instance
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def configured_instance
|
25
|
+
Box::Office.config.instance
|
26
|
+
end
|
27
|
+
|
28
|
+
def configured_pool_size
|
29
|
+
Box::Office.config.pool_size
|
30
|
+
end
|
31
|
+
|
32
|
+
def connection_pool
|
33
|
+
ConnectionPool.new(size: configured_pool_size) { configured_instance }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Box
|
4
|
+
module Office
|
5
|
+
class Janitor
|
6
|
+
class << self
|
7
|
+
include Box::Office::Connection
|
8
|
+
LOCKED_QUEUE_KEY = "box-office:locked:queues"
|
9
|
+
|
10
|
+
def lock(queue_name)
|
11
|
+
with_connection { |conn| conn.sadd(LOCKED_QUEUE_KEY, queue_name) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def locked?(queue_name)
|
15
|
+
with_connection { |conn| conn.sismember(LOCKED_QUEUE_KEY, queue_name) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def locked_queues
|
19
|
+
with_connection { |conn| conn.smembers LOCKED_QUEUE_KEY }
|
20
|
+
end
|
21
|
+
|
22
|
+
def unlock(queue_name)
|
23
|
+
with_connection { |conn| conn.srem(LOCKED_QUEUE_KEY, queue_name) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Box
|
4
|
+
module Office
|
5
|
+
class Queue
|
6
|
+
include Box::Office::Connection
|
7
|
+
LIMIT = 100
|
8
|
+
|
9
|
+
attr_reader :name
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@name = name
|
13
|
+
end
|
14
|
+
|
15
|
+
def clear
|
16
|
+
with_connection { |conn| conn.del(name) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def members(limit: LIMIT)
|
20
|
+
with_connection { |conn| conn.lrange(name, 0, limit - 1) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def empty?
|
24
|
+
length.zero?
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
with_connection { |conn| conn.llen(name) }
|
29
|
+
end
|
30
|
+
alias size length
|
31
|
+
|
32
|
+
def push(*msg)
|
33
|
+
with_connection { |conn| conn.lpush(name, *msg) }
|
34
|
+
end
|
35
|
+
alias << push
|
36
|
+
|
37
|
+
def remove(msg)
|
38
|
+
with_connection { |conn| conn.lrem(name, 0, msg) }
|
39
|
+
end
|
40
|
+
alias >> remove
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Box
|
4
|
+
module Office
|
5
|
+
class Showing
|
6
|
+
include Connection
|
7
|
+
|
8
|
+
attr_accessor :track_fulfilled, :showings, :capacity
|
9
|
+
attr_reader :name, :booth
|
10
|
+
|
11
|
+
delegate :config, to: Box::Office
|
12
|
+
|
13
|
+
def initialize(name: config.default_name, track_fulfilled: config.track_fulfilled,
|
14
|
+
showings: config.showings, capacity: config.capacity)
|
15
|
+
@name = name
|
16
|
+
@track_fulfilled = track_fulfilled
|
17
|
+
@showings = showings
|
18
|
+
@capacity = capacity
|
19
|
+
|
20
|
+
@booth = Booth.new(showing: self)
|
21
|
+
|
22
|
+
setup_reserved_queues
|
23
|
+
end
|
24
|
+
|
25
|
+
Box::Office.config.single_queues.each do |que|
|
26
|
+
define_method que do
|
27
|
+
Queue.new send("#{que}_key")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def fulfill(queue, msg)
|
32
|
+
send(config.fulfilled) << msg if track_fulfilled?
|
33
|
+
queue >> msg
|
34
|
+
end
|
35
|
+
|
36
|
+
def push(*msg)
|
37
|
+
with_connection { |conn| conn.lpush(send("#{config.standby}_key"), *msg) }
|
38
|
+
end
|
39
|
+
alias << push
|
40
|
+
|
41
|
+
def reserve(capacity: self.capacity, block_unlock: true)
|
42
|
+
with_connection do |conn|
|
43
|
+
booth.first_available_opening(conn) do |opening|
|
44
|
+
Janitor.lock(opening.name) if config.lock_reserved?
|
45
|
+
conn.rpoplpush(send("#{config.standby}_key"), opening.name) while openings?(opening, capacity)
|
46
|
+
|
47
|
+
if block_given?
|
48
|
+
yield opening, opening.members(limit: capacity)
|
49
|
+
Janitor.unlock(opening.name) if config.lock_reserved? && block_unlock
|
50
|
+
end
|
51
|
+
rescue
|
52
|
+
Janitor.unlock(opening.name)
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias pop reserve
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
Box::Office.config.single_queues.each do |que|
|
62
|
+
define_method "#{que}_key" do
|
63
|
+
"box-office:#{name.parameterize}:#{que}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Box::Office.config.reserved.tap do |que|
|
68
|
+
define_method "#{que}_key" do |idx|
|
69
|
+
"box-office:#{name.parameterize}:#{que}-#{idx}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def openings?(queue, capacity)
|
74
|
+
queue.length < capacity && !send(config.standby).empty?
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup_reserved_queues
|
78
|
+
Box::Office.config.reserved.tap do |que|
|
79
|
+
define_singleton_method que do |idx = 1|
|
80
|
+
raise OutOfRange, "#{idx} is out of range of available showings" unless (1..showings).to_a.include? idx
|
81
|
+
|
82
|
+
Queue.new send("#{que}_key", idx)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: box-office
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Drew Monroe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redlock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '10.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '10.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.61.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.61.0
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- dvmonroe6@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".travis.yml"
|
162
|
+
- CODE_OF_CONDUCT.md
|
163
|
+
- Gemfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- bin/console
|
168
|
+
- bin/setup
|
169
|
+
- box-office.gemspec
|
170
|
+
- lib/box/office.rb
|
171
|
+
- lib/box/office/booth.rb
|
172
|
+
- lib/box/office/configuration.rb
|
173
|
+
- lib/box/office/connection.rb
|
174
|
+
- lib/box/office/janitor.rb
|
175
|
+
- lib/box/office/queue.rb
|
176
|
+
- lib/box/office/showing.rb
|
177
|
+
- lib/box/office/version.rb
|
178
|
+
homepage: http://github.com/dvmonroe/box-office
|
179
|
+
licenses:
|
180
|
+
- MIT
|
181
|
+
metadata: {}
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
requirements: []
|
197
|
+
rubygems_version: 3.0.1
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Reliable redis queueing
|
201
|
+
test_files: []
|