lib/dispatch-rider/publisher/base.rb in dispatch-rider-1.6.2 vs lib/dispatch-rider/publisher/base.rb in dispatch-rider-1.7.0

- old
+ new

@@ -28,14 +28,23 @@ @publisher = publisher end # @param [Hash] body def publish(body) - raise ArgumentError, 'body should be a hash' unless body.kind_of?(Hash) + validate_body(body) publisher.publish(destinations: destinations, message: { subject: subject, body: body }) end + # @param [Hash] body + # @param [Time] at + def publish_later(body, at:) + validate_body(body) + DispatchRider::ScheduledJob.create! scheduled_at: at, + destinations: destinations, + message: { subject: subject, body: body } + end + private def publisher @publisher || self.class.default_publisher end @@ -44,8 +53,12 @@ self.class.instance_variable_get(:@destinations) end def subject self.class.instance_variable_get(:@subject) + end + + def validate_body(body) + raise ArgumentError, 'body should be a hash' unless body.is_a?(Hash) end end end