Class: Specbandit::Publisher
- Inherits:
-
Object
- Object
- Specbandit::Publisher
- Defined in:
- lib/specbandit/publisher.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#key_ttl ⇒ Object
readonly
Returns the value of attribute key_ttl.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(key: Specbandit.configuration.key, key_ttl: Specbandit.configuration.key_ttl, queue: nil, output: $stdout) ⇒ Publisher
constructor
A new instance of Publisher.
-
#publish(files: [], pattern: nil, reset: false) ⇒ Object
Resolve files from the three input sources (priority: stdin > pattern > args) and push them onto the Redis queue.
Constructor Details
#initialize(key: Specbandit.configuration.key, key_ttl: Specbandit.configuration.key_ttl, queue: nil, output: $stdout) ⇒ Publisher
Returns a new instance of Publisher.
9 10 11 12 13 14 15 |
# File 'lib/specbandit/publisher.rb', line 9 def initialize(key: Specbandit.configuration.key, key_ttl: Specbandit.configuration.key_ttl, queue: nil, output: $stdout) @key = key @key_ttl = key_ttl @queue = queue || RedisQueue.new @output = output end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/specbandit/publisher.rb', line 7 def key @key end |
#key_ttl ⇒ Object (readonly)
Returns the value of attribute key_ttl.
7 8 9 |
# File 'lib/specbandit/publisher.rb', line 7 def key_ttl @key_ttl end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/specbandit/publisher.rb', line 7 def output @output end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/specbandit/publisher.rb', line 7 def queue @queue end |
Instance Method Details
#publish(files: [], pattern: nil, reset: false) ⇒ Object
Resolve files from the three input sources (priority: stdin > pattern > args) and push them onto the Redis queue.
With reset: true the key is emptied first, so the queue ends up holding
exactly this work list even if an earlier attempt already pushed one.
Returns the number of files enqueued.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/specbandit/publisher.rb', line 24 def publish(files: [], pattern: nil, reset: false) resolved = resolve_files(files: files, pattern: pattern) if resolved.empty? output.puts '[specbandit] No files to enqueue.' return 0 end # Only reset once there is something to put in its place. Clearing on an # empty push would drop the marker too and leave workers crashing on a # key that looks like it was never published. reset_key if reset push_ms = measure { queue.push(key, resolved, ttl: key_ttl) } # Record a durable "published" marker so workers can tell a drained # queue ("worker arriving late", OK) apart from one that was never # pushed ("you didn't push work", crash). Redis auto-deletes empty # lists, so the list itself cannot carry this signal. mark_ms = measure { queue.mark_published(key, ttl: key_ttl) } output.puts "[specbandit] Enqueued #{resolved.size} files onto key '#{key}' (TTL: #{key_ttl}s)." output.puts format('[specbandit] Redis latency: push %.1fms, mark published %.1fms.', push_ms, mark_ms) resolved.size end |