Sha256: b540cbf747037d37402f8d599d38e97f2acabfa32bfc0d6630c3275563dff6f2

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

module Sidejobs
  module Extensions
    module ActiveJob
      module QueueAdapters
        class SidejobsAdapter

          def enqueue(job)
            Sidejobs.queue.add(
              job.serialize,
              queue: job.queue_name,
              priority: calculate_priority(job.queue_name)
            )
          end

          def enqueue_at(job, timestamp)
            Sidejobs.queue.add(
              job.serialize,
              queue: job.queue_name,
              priority: calculate_priority(job.queue_name),
              schedule_at: Time.at(timestamp)
            )
          end

          private

          def calculate_priority(queue)
            case queue
            when 'mailers'
              80
            when 'high_priority'
              60
            when 'default'
              40
            when 'low_priority'
              20
            else
              0
            end
          end

        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidejobs-5.1.1 lib/sidejobs/extensions/active_job/queue_adapter.rb
sidejobs-5.1.0 lib/sidejobs/extensions/active_job/queue_adapter.rb