Sha256: fa32d6885181f69ce9a8799252da3ddb98b0287b38a39a90eaeb6fa27964daef

Contents?: true

Size: 1.29 KB

Versions: 11

Compression:

Stored size: 1.29 KB

Contents

module Pageflow
  class PollZencoderJob < ApplicationJob
    queue_as :resizing

    include StateMachineJob

    def perform_with_result(file, options, api = ZencoderApi.instance)
      options ||= {}

      catch(:halt) do
        poll_zencoder(file, api)
        fetch_input_details(file, api)
        file.post_process_encoded_files unless options[:skip_post_processing]

        :ok
      end
    ensure
      file.save!
    end

    private

    def poll_zencoder(file, api)
      info = api.get_info(file.job_id)

      file.encoding_progress = info[:finished] ? 100 : info[:progress];
      file.encoding_error_message = nil

      if info[:state] === 'failed'
        throw(:halt, :error)
      elsif !info[:finished]
        throw(:halt, :pending)
      end
    rescue ZencoderApi::RecoverableError => e
      file.encoding_error_message = e.message
      throw(:halt, :pending)
    rescue ZencoderApi::Error => e
      file.encoding_error_message = e.message
      raise
    end

    def fetch_input_details(file, api)
      file.meta_data_attributes = api.get_details(file.job_id)
    rescue ZencoderApi::RecoverableError => e
      file.encoding_error_message = e.message
      throw(:halt, :pending)
    rescue ZencoderApi::Error => e
      file.encoding_error_message = e.message
      raise
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pageflow-17.0.4 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-17.0.3 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-17.0.2 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-17.0.1 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-17.0.0 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-16.2.0 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-16.1.0 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-16.0.0 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-15.8.0 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-15.7.1 app/jobs/pageflow/poll_zencoder_job.rb
pageflow-15.7.0 app/jobs/pageflow/poll_zencoder_job.rb