Sha256: d8d6de7a9ffc42ea32d9eafa1ae6fa8b71faaf36351d80034c5700d024c7d94b

Contents?: true

Size: 1020 Bytes

Versions: 13

Compression:

Stored size: 1020 Bytes

Contents

module Workarea
  class IndexReleaseScheduleChange
    include Sidekiq::Worker
    include Sidekiq::CallbacksWorker

    sidekiq_options(
      enqueue_on: {
        Release => [:save, :destroy],
        only_if: -> { publish_at_changed? || destroyed? },
        with: -> { [id, publish_at_was, publish_at] }
      },
      queue: 'releases'
    )

    def perform(id, previous_publish_at, new_publish_at)
      # When destroyed, changesets for the release ID will still exist and be used to update the index
      rescheduled_release = Release.find_or_initialize_by(id: id)

      earlier, later = if rescheduled_release.persisted? && previous_publish_at.present? && new_publish_at.present?
        [previous_publish_at, new_publish_at].sort
      elsif previous_publish_at.present?
        [previous_publish_at, nil]
      else
        [new_publish_at, nil]
      end

      IndexReleaseSchedulePreviews
        .new(release: rescheduled_release, starts_at: earlier, ends_at: later)
        .perform
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.26 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.25 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.23 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.22 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.21 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.20 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.19 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.18 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.17 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.16 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.15 app/workers/workarea/index_release_schedule_change.rb
workarea-core-3.5.14 app/workers/workarea/index_release_schedule_change.rb