Sha256: fc94397ed9b2249ae31be2fefaa6fc062d66de49121df78175cae1e3637aa2bc

Contents?: true

Size: 669 Bytes

Versions: 1

Compression:

Stored size: 669 Bytes

Contents

# encoding: utf-8

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")
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 app/models/autopublisher.rb