Module: Cuniculus::CuniculusMethods

Included in:
Cuniculus
Defined in:
lib/cuniculus/core.rb

Overview

Core Cuniculus methods

Instance Method Summary collapse

Instance Method Details

#convert_exception_class(exception, klass) ⇒ Cuniculus::Error

Convert the input ‘exception` to the given class. The given class should be Error or a subclass. Returns an instance of `klass` with the message and backtrace of `exception`.

Parameters:

  • exception (Exception)

    The exception being wrapped

  • klass (Cuniculus::Error)

    The subclass of ‘Cuniculus::Error`

Returns:



29
30
31
32
33
34
35
36
# File 'lib/cuniculus/core.rb', line 29

def convert_exception_class(exception, klass)
  return exception if exception.is_a?(klass)

  e = klass.new("#{exception.class}: #{exception.message}")
  e.wrapped_exception = exception
  e.set_backtrace(exception.backtrace)
  e
end

#dump_job(job) ⇒ Object

Serializes a Ruby object for publishing to RabbitMQ.



17
18
19
# File 'lib/cuniculus/core.rb', line 17

def dump_job(job)
  ::JSON.dump(job)
end

#load_job(rmq_msg) ⇒ Object

Convert a RabbitMQ message into Ruby object for processing.



12
13
14
# File 'lib/cuniculus/core.rb', line 12

def load_job(rmq_msg)
  ::JSON.parse(rmq_msg)
end

#mark_timeObject



38
39
40
# File 'lib/cuniculus/core.rb', line 38

def mark_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end