Sha256: bfe010a1249df5904c8ee40d80d65877d496912a11a46afa94a80b13db945c75
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module Tennis module Worker module Generic autoload :BeforeHook, "tennis/worker/generic/before_hook" autoload :Serialize, "tennis/worker/generic/serialize" autoload :Options, "tennis/worker/generic/options" def self.included(base) base.extend BeforeHook base.extend Serialize base.extend Options 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 send_work(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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tennis-jobs-0.3.1 | lib/tennis/worker/generic.rb |
tennis-jobs-0.3.0 | lib/tennis/worker/generic.rb |