Module: Chutzen
- Defined in:
- lib/chutzen.rb,
lib/chutzen/job.rb,
lib/chutzen/apply.rb,
lib/chutzen/demux.rb,
lib/chutzen/shell.rb,
lib/chutzen/signal.rb,
lib/chutzen/worker.rb,
lib/chutzen/command.rb,
lib/chutzen/version.rb,
lib/chutzen/watcher.rb,
lib/chutzen/template.rb,
lib/chutzen/dictionary.rb,
lib/chutzen/expression.rb,
lib/chutzen/notification.rb,
lib/chutzen/runtime_error.rb,
lib/chutzen/standard_error.rb,
lib/chutzen/template_parser.rb,
lib/chutzen/expression_parser.rb,
lib/chutzen/template/syntax_error.rb,
lib/chutzen/expression/lookup_error.rb,
lib/chutzen/expression/syntax_error.rb,
lib/chutzen/command/execution_failed.rb
Overview
Implements a toolkit to perform batch processing.
Defined Under Namespace
Classes: Apply, Command, Demux, Dictionary, Expression, ExpressionParser, Job, Notification, RuntimeError, Shell, Signal, StandardError, Template, TemplateParser, Watcher, Worker
Constant Summary collapse
- VERSION =
'0.8.0'
Class Attribute Summary collapse
-
.sidekiq_queue ⇒ Object
Returns the value of attribute sidekiq_queue.
Class Method Summary collapse
-
.dequeue(query) ⇒ Object
Dequeue all jobs that match the query.
-
.emit_signal(signal, queue:, expires_at: nil, expires_in: nil) ⇒ Object
Enqueue a Sidekiq job that will eventually process the signal.
-
.expiration_since_epoch(expires_at: nil, expires_in: nil) ⇒ Object
Computes the expiration in seconds since epoch.
-
.perform(description) ⇒ Object
Immediately perform the description.
-
.perform_async(description) ⇒ Object
Enqueue a Sidekiq job that will eventually perform the job in the description.
Class Attribute Details
.sidekiq_queue ⇒ Object
Returns the value of attribute sidekiq_queue.
35 36 37 |
# File 'lib/chutzen.rb', line 35 def sidekiq_queue @sidekiq_queue end |
Class Method Details
.dequeue(query) ⇒ Object
Dequeue all jobs that match the query. Uses Chutzen’s own query format.
66 67 68 69 70 71 72 |
# File 'lib/chutzen.rb', line 66 def self.dequeue(query) Sidekiq::Queue.new(sidekiq_queue).each do |job| dictionary = Chutzen::Dictionary.new(JSON.parse(job.args.first)) expression = Chutzen::Expression.new(query, dictionary) job.delete if expression.result end end |
.emit_signal(signal, queue:, expires_at: nil, expires_in: nil) ⇒ Object
Enqueue a Sidekiq job that will eventually process the signal. It’s customary for each Chutzen host to have its own control queue next to the regular job queue. Use the name of that queue when you want to target a specific host. Otherwise the signal will be processed by one random host.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/chutzen.rb', line 53 def self.emit_signal(signal, queue:, expires_at: nil, expires_in: nil) Chutzen::Signal.set( queue: queue ).perform_async( signal, expiration_since_epoch( expires_at: expires_at, expires_in: expires_in ) ) end |
.expiration_since_epoch(expires_at: nil, expires_in: nil) ⇒ Object
Computes the expiration in seconds since epoch. When neither expires_at or expires_in is specified it will default to 30 seconds from now.
81 82 83 84 85 86 |
# File 'lib/chutzen.rb', line 81 def self.expiration_since_epoch(expires_at: nil, expires_in: nil) return expires_at.to_i if expires_at expires_in ||= 30 (Time.now + expires_in).to_i end |