Class: Yes::Core::Commands::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/commands/notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Notifier

Returns a new instance of Notifier.

Parameters:

  • options (Hash) (defaults to: {})

    notifier options

Options Hash (options):

  • :channel (String)

    the notification channel



14
15
16
# File 'lib/yes/core/commands/notifier.rb', line 14

def initialize(options = {})
  @channel = options[:channel]
end

Class Method Details

.with_batch_notification(notifiers, batch_id, commands, transaction = nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/yes/core/commands/notifier.rb', line 55

def self.with_batch_notification(notifiers, batch_id, commands, transaction = nil)
  notifiers.each { _1.notify_batch_started(batch_id, transaction, commands) }
  response = yield
  notifiers.each { _1.notify_batch_finished(batch_id, transaction, response) }

  response
end

Instance Method Details

#notify_batch_finished(batch_id, transaction = nil, responses = nil) ⇒ Object

Implement this method to notify that a batch has finished processing

Parameters:

  • batch_id (String)

    batch id of the batch that has finished processing

  • transaction (TransactionDetails) (defaults to: nil)

    the transaction details of the current transaction

  • responses (Array<Response>) (defaults to: nil)

    the responses of the commands that were processed

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/yes/core/commands/notifier.rb', line 30

def notify_batch_finished(batch_id, transaction = nil, responses = nil)
  raise NotImplementedError
end

#notify_batch_started(batch_id, transaction = nil, commands = nil) ⇒ Object

Implement this method to notify that a batch has started processing

Parameters:

  • batch_id (String)

    batch id of the batch that has started processing

  • transaction (TransactionDetails) (defaults to: nil)

    the transaction details of the current transaction

  • commands (Array<Command>) (defaults to: nil)

    the commands that are being processed

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/yes/core/commands/notifier.rb', line 22

def notify_batch_started(batch_id, transaction = nil, commands = nil)
  raise NotImplementedError
end

#notify_command_response(cmd_response) ⇒ Object

Implement this method to notify that a command response has been received

Parameters:

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/yes/core/commands/notifier.rb', line 36

def notify_command_response(cmd_response)
  raise NotImplementedError
end

#with_batch_notification(batch_id, commands, transaction = nil) { ... } ⇒ Array<Response>

Wraps the given block in a batch notification.

Parameters:

  • batch_id (String)

    the batch id

  • commands (Array<Command>)

    the commands being processed in the batch

  • transaction (TransactionDetails) (defaults to: nil)

    the transaction details of the current transaction

Yields:

  • executes commands within the batch notification

Yield Returns:

  • (Array<Response>)

    responses from the executed commands

Returns:

  • (Array<Response>)

    responses from the executed commands



47
48
49
50
51
52
53
# File 'lib/yes/core/commands/notifier.rb', line 47

def with_batch_notification(batch_id, commands, transaction = nil)
  notify_batch_started(batch_id, transaction, commands)
  response = yield
  notify_batch_finished(batch_id, transaction, response)

  response
end