Sha256: be37aabf3fab609d82fe7e55208b4a6d72825ca9ad4c8d6719457ed331790ee8

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

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

4 entries across 4 versions & 1 rubygems

Version Path
acidic_job-1.0.0.pre13 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre12 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre11 lib/acidic_job/staging.rb
acidic_job-1.0.0.pre10 lib/acidic_job/staging.rb