Sha256: 785c566787510daba1ae4972aeaf3c97f21a74b09cb7d0d4757fd32c373501d7

Contents?: true

Size: 735 Bytes

Versions: 24

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

class Autopublisher
  class << self
    def run!(_options = {})
      if due_pages.any?
        PagesCore::CacheSweeper.once do
          due_pages.each do |p|
            p.update(autopublish: false)
          end
        end
      end
      queue!
    end

    def queue!
      return unless queued_pages.any?

      PagesCore::AutopublishJob
        .set(wait_until: queued_pages.first.published_at)
        .perform_later
    end

    protected

    def queued_pages
      Page.where(autopublish: true)
          .order("published_at ASC")
          .in_locale(I18n.default_locale)
    end

    def due_pages
      queued_pages.where("published_at < ?", (Time.now.utc + 2.minutes))
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pages_core-3.14.0 app/models/autopublisher.rb
pages_core-3.13.0 app/models/autopublisher.rb
pages_core-3.12.7 app/models/autopublisher.rb
pages_core-3.12.6 app/models/autopublisher.rb
pages_core-3.12.5 app/models/autopublisher.rb
pages_core-3.12.4 app/models/autopublisher.rb
pages_core-3.12.3 app/models/autopublisher.rb
pages_core-3.12.2 app/models/autopublisher.rb
pages_core-3.12.1 app/models/autopublisher.rb
pages_core-3.12.0 app/models/autopublisher.rb
pages_core-3.11.3 app/models/autopublisher.rb
pages_core-3.11.2 app/models/autopublisher.rb
pages_core-3.11.1 app/models/autopublisher.rb
pages_core-3.11.0 app/models/autopublisher.rb
pages_core-3.10.2 app/models/autopublisher.rb
pages_core-3.10.1 app/models/autopublisher.rb
pages_core-3.9.2 app/models/autopublisher.rb
pages_core-3.9.1 app/models/autopublisher.rb
pages_core-3.9.0 app/models/autopublisher.rb
pages_core-3.8.3 app/models/autopublisher.rb