Class: Colore::Sidekiq::ConversionWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/sidekiq_workers.rb

Overview

This worker converts a document file to a new format and stores it.

Instance Method Summary collapse

Instance Method Details

#perform(doc_key_str, version, filename, action, callback_url = nil) ⇒ Object

Converts a document file to a new format. The converted file will be stored in the document version directory. If the callback_url is specified, the [CallbackWorker] will be called to POST the conversion results back to the client application.

Parameters:

  • doc_key_str (String)

    the serialised [DocKey]

  • version (String)

    the file version

  • filename (String)

    the file to convert

  • action (String)

    the conversion to perform

  • callback_url (String) (defaults to: nil)

    optional callback URL


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sidekiq_workers.rb', line 24

def perform doc_key_str, version, filename, action, callback_url=nil
  doc_key = DocKey.parse doc_key_str
  new_filename = Converter.new.convert doc_key, version, filename, action
  status = 200
  message = "Document converted"
rescue Heathen::TaskNotFound => e
  logger.warn "#{e.message}, will not attempt to re-process this request"
  log_error e, doc_key_str, filename, action
  status = 400
  message = e.message
rescue StandardError => e
  logger.warn "#{e.message}, will not attempt to re-process this request"
  log_error e, doc_key_str, filename, action
  status = 500
  message = e.message
ensure
  CallbackWorker.perform_async doc_key_str, version, action, new_filename, callback_url, status, message if callback_url
end