Class: Chutzen::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/chutzen/notification.rb

Overview

Helper class to push a Sidekiq job on the specified callback queue with the specified class and arguments.

Class Method Summary collapse

Class Method Details

.defaultsObject

Returns defaults for a Sidekiq job. See Sidekiq documentation for value params. We suggest using ‘queue’, ‘class’, and ‘args’.



9
10
11
# File 'lib/chutzen/notification.rb', line 9

def self.defaults
  { 'queue' => 'default' }
end

.perform_async(job, payload) ⇒ Object

Schedules a notification by creating a Sidekiq job using the job description and a Ruby object as a payload.

Notification.perform_async(
  { 'class' => 'MyApplication::Result' },
  { 'filename' => 'ok.txt', 'name' => 'ok' }
)

The payload is serialized as JSON to reduce potential interoperability problems and to make it easier to write forward and backward support for the worker classes.



24
25
26
27
28
29
30
# File 'lib/chutzen/notification.rb', line 24

def self.perform_async(job, payload)
  Sidekiq::Client.push(
    defaults.merge(
      job.merge('args' => [JSON.dump(payload)])
    )
  )
end