lib/resque-bus.rb in resque-bus-0.3.2 vs lib/resque-bus.rb in resque-bus-0.3.3
- old
+ new
@@ -144,19 +144,32 @@
yield
ensure
I18n.locale = original_locale unless original_locale == false
Time.zone = original_timezone unless original_timezone == false
end
+
+ def before_publish=(proc)
+ @before_publish_callback = proc
+ end
+
+ def before_publish_callback(attributes)
+ if @before_publish_callback
+ @before_publish_callback.call(attributes)
+ end
+ end
+
def publish_metadata(event_type, attributes={})
# TODO: "bus_app_key" => application.app_key ?
bus_attr = {"bus_published_at" => Time.now.to_i, "bus_event_type" => event_type}
bus_attr["bus_id"] = "#{Time.now.to_i}-#{generate_uuid}"
bus_attr["bus_app_hostname"] = hostname
bus_attr["bus_locale"] = I18n.locale.to_s if defined?(I18n) && I18n.respond_to?(:locale) && I18n.locale
bus_attr["bus_timezone"] = Time.zone.name if defined?(Time) && Time.respond_to?(:zone) && Time.zone
- bus_attr.merge(attributes || {})
+ out = bus_attr.merge(attributes || {})
+ ResqueBus.before_publish_callback(out)
+ out
end
def generate_uuid
require 'securerandom' unless defined?(SecureRandom)
return SecureRandom.uuid
@@ -222,9 +235,10 @@
# used by tests
@redis = nil # clear instance of redis
@dispatcher = nil
@default_app_key = nil
@default_queue = nil
+ @before_publish_callback = nil
end
def incoming_queue
"resquebus_incoming"
end
\ No newline at end of file