docbrown/app/observers/article_observer.rb
Anna Buianova 18d1300341 Moved SlackBot.delay.ping calls to ActiveJob #3136 (#3139)
* Moved SlackBot.delay.ping calls to ActiveJob

* Removed unused user creation from the spec
2019-06-12 09:23:37 -04:00

18 lines
613 B
Ruby

class ArticleObserver < ApplicationObserver
def after_save(article)
return if Rails.env.development?
ping_new_article(article)
rescue StandardError => e
Rails.logger.error(e)
end
def ping_new_article(article)
return unless article.published && article.published_at > 30.seconds.ago
SlackBotPingJob.perform_later message: "New Article Published: #{article.title}\nhttps://dev.to#{article.path}",
channel: "activity",
username: "article_bot",
icon_emoji: ":writing_hand:"
end
end