Class: Articles::PublishScheduled
- Inherits:
-
BaseService
- Object
- BaseService
- Articles::PublishScheduled
- Defined in:
- app/services/postnhost/publishing/articles/publish_scheduled.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(article_id:, job_id:) ⇒ PublishScheduled
constructor
A new instance of PublishScheduled.
Constructor Details
#initialize(article_id:, job_id:) ⇒ PublishScheduled
Returns a new instance of PublishScheduled.
4 5 6 7 |
# File 'app/services/postnhost/publishing/articles/publish_scheduled.rb', line 4 def initialize(article_id:, job_id:) @article_id = article_id @job_id = job_id end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/postnhost/publishing/articles/publish_scheduled.rb', line 9 def call article = Article.find_by(id: article_id) return failure("Article was not found", status: :not_found) unless article return failure("Article is not due for this job") unless due_for_this_job?(article) snapshot = Revision.hold do article.lock! Articles::SnapshotWriter.new(article:).call end success(snapshot, status: :ok) rescue Error => e record_publication_error(article, e.) failure(e.) rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e record_publication_error(article, e.) failure(e.) end |