class Lato::ApplicationJob
ApplicationJob.
def manage_operation
def manage_operation @operation = Lato::Operation.find(arguments.first[:_operation_id]) if arguments.first && arguments.first.is_a?(Hash) && !arguments.first[:_operation_id].blank? @operation&.running begin yield @operation&.completed rescue StandardError => e return @operation.failed(e.message) if @operation raise e end end
def operation?
def operation? !!@operation end
def operation_input_file_attachment
def operation_input_file_attachment @operation.input_file.attached? ? @operation.input_file : nil end
def save_operation_output_file(file_path)
def save_operation_output_file(file_path) return false unless operation? file = File.open(file_path) file_name = File.basename(file_path) @operation.output_file.attach( io: file, filename: file_name ) end
def save_operation_output_message(message)
def save_operation_output_message(message) return false unless operation? @operation.update( active_job_output: @operation.active_job_output.merge(_message: message) ) true end
def update_operation_percentage(percentage)
def update_operation_percentage(percentage) return false unless operation? @operation.update( percentage: percentage ) end