From 861f84eb9d5c01681af040274f5e104b5ad0a1ca Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 14 Oct 2013 22:28:31 -0500 Subject: [PATCH] No longer recommend inheriting from Struct.new Inheriting from Struct.new can lead to this error: "TypeError: superclass mismatch for class SomeJob" Details: http://www.benjaminoakes.com/2013/10/15/superclass-mismatch-when-inheriting-from-struct-new/ --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d2224f05..8f675c5e9 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ Custom Jobs Jobs are simple ruby objects with a method called perform. Any object which responds to perform can be stuffed into the jobs table. Job objects are serialized to yaml so that they can later be resurrected by the job runner. ```ruby -class NewsletterJob < Struct.new(:text, :emails) +NewsletterJob = Struct.new(:text, :emails) do def perform emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) } end @@ -238,7 +238,7 @@ Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...', Customers.find(:all).co ``` To set a per-job max attempts that overrides the Delayed::Worker.max_attempts you can define a max_attempts method on the job ```ruby -class NewsletterJob < Struct.new(:text, :emails) +NewsletterJob = Struct.new(:text, :emails) do def perform emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) } end