Sha256: ee0f6d93e8235b7928905f8e12295b77f6d76631b94eee0237ad4f5dfc3c44be

Contents?: true

Size: 1007 Bytes

Versions: 9

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"
require "global_id/locator"

module AcidicJob
  module Staging
    extend ActiveSupport::Concern

    def delete_staged_job_record
      return unless was_staged_job?

      staged_job_run.delete
      true
    rescue ActiveRecord::RecordNotFound
      true
    end

    def was_staged_job?
      identifier.start_with? "STG_"
    end

    def staged_job_run
      # "STG_#{idempotency_key}__#{encoded_global_id}"
      encoded_global_id = identifier.split("__").last
      staged_job_gid = "gid://#{Base64.decode64(encoded_global_id)}"

      GlobalID::Locator.locate(staged_job_gid)
    end

    def identifier
      return jid if defined?(jid) && !jid.nil?
      return job_id if defined?(job_id) && !job_id.nil?

      # might be defined already in `with_acidity` method
      @__acidic_job_idempotency_key ||= IdempotencyKey.value_for(self, @__acidic_job_args, @__acidic_job_kwargs)

      @__acidic_job_idempotency_key
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
acidic_job-1.0.0.pre22 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre21 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre20 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre19 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre18 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre17 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre16 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre15 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre14 lib/acidic_job/staging.rb