Last active
December 31, 2015 04:09
-
-
Save angelsystem/7932465 to your computer and use it in GitHub Desktop.
delayed job hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Newsletter < ActiveRecord::Base | |
def deliver | |
sleep 5 # simulate long newsletter delivery | |
update_attribute(:delivered_at, Time.zone.now) | |
end | |
handle_asynchronously :deliver | |
end | |
=============== | |
class NewslettersController < ApplicationController | |
def deliver | |
@newsletter = Newsletter.find(params[:id]) | |
@newsletter.deliver | |
redirect_to newsletters_url, notice: "enviado newsletters" | |
end | |
end | |
================ | |
class ParanoidNewsletter < Newsletter | |
def before | |
p "before" | |
end | |
def after(job) | |
p "after" | |
end | |
def success(job) | |
p "sucess" | |
p job | |
record_stat 'newsletter/success' | |
end | |
end | |
========== | |
#views newsletter/index.html.erb | |
<% @newsletters.each do |newsletter| %> | |
<%= link_to "Deliver", deliver_newsletter_path(newsletter), method: :post %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment