Sha256: 53d4f2c772c4fde7f538cd25e1e925bff23aea2ba38d3787f91dd1f1a8370454
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
module Tennis module Worker module Generic autoload :BeforeHook, "tennis/worker/generic/before_hook" autoload :Serialize, "tennis/worker/generic/serialize" def self.included(base) base.extend BeforeHook base.extend Serialize base.extend DSL base.worker = Class.new do @@parent = base include Sneakers::Worker from_queue @@parent.name def work(message) message = @@parent._apply_serializer(:load, message) @@parent._process_before_hooks(message, self) instance_exec(message, &@@parent._work) end end end module DSL attr_accessor :worker def work(&block) @_work = block end def _work @_work ||= ->(_){ ack! } end def execute(message) message = _apply_serializer(:dump, message) if Tennis.config.async publisher_opts = worker.queue_opts.select do |opt_name, _| opt_name == :exchange || opt_name == :exchange_type end publisher = Sneakers::Publisher.new(publisher_opts) publisher.publish(message, to_queue: worker.queue_name) publisher.instance_variable_get(:@bunny).close else worker.new.work(message) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tennis-jobs-0.1.0 | lib/tennis/worker/generic.rb |