Sha256: dc23ab5370e22a6227124d6d94522097cbe9e1873e9f629f0c129d315e6a25a5

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

# typed: true
module UpGush
  module Models
    class WorkflowStep < ActiveRecord::Base
      extend T::Sig

      self.table_name = :workflow_steps

      # :nocov:
      if ENV['TEST_MODE']
        serialize :incoming, Array
        serialize :outgoing, Array
      end
      # :nocov:

      belongs_to :workflow, class_name: 'UpGush::Models::Workflow'

      scope :without_dependencies, -> { where(incoming: []) }
      scope :cleanup_job, -> { where(klass: 'UpGush::Jobs::ScheduleCleanup') }
      scope :started, -> { where.not(started_at: nil) }
      scope :not_started, -> { where(started_at: nil) }
      scope :finished, -> { where.not(finished_at: nil) }
      scope :not_finished, -> { where(finished_at: nil) }
      scope :enqueued, -> { where.not(enqueued_at: nil) }

      scope :executed, -> { started.finished.order(started_at: :desc) }
      scope :started_not_finished, -> { started.not_finished.order(started_at: :desc) }
      scope :enqueued_not_started, -> { enqueued.not_started.order(enqueued_at: :desc) }

      scope :unfinished_resume, -> { started_not_finished.where(resumed: true) }

      sig { returns(String) }
      def name
        "#{klass}|#{uuid}"
      end

      sig { params(redis_workflow_id: String).returns(T::Hash[Symbol, T.untyped]) }
      def gush_job_attrs(redis_workflow_id)
        attrs = attributes.deep_symbolize_keys.except(:id, :updated_at, :created_at, :workflow_id)
        attrs[:id] = attrs.delete(:uuid)
        attrs[:workflow_id] = redis_workflow_id

        attrs
      end

      sig { params(redis_workflow_id: String).returns(Gush::Job) }
      def to_gush_job(redis_workflow_id)
        Gush::Job.new(gush_job_attrs(redis_workflow_id))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
up_gush-3.0.0.1 lib/up_gush/models/workflow_step.rb