Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-includes/theme.php on line 623

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/custom_posts/custom_posts.php on line 22

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 46

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 67

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 75

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/pukiwiki.php on line 92

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiRender.php on line 70

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 181

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 538

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 695

Deprecated: Assigning the return value of new by reference is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/modPukiWiki/class/PukiWikiElement.php on line 1087

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112

Deprecated: Function ereg() is deprecated in /home/users/1/fool.jp-ichi/web/blog/wp-content/plugins/wp-ban/wp-ban.php on line 112
[rails] delayed_jobでjob単位で再試行回数を設定する | おれせか
おれせか

なんかそれっぽいのをうにうに。

https://github.com/collectiveidea/delayed_job

同じ種類のJobなんだけど、実行するタイミングや状況によって失敗時の再試行回数かえたいなーっていう要件があったので色々ごにょごにょしたメモ。

ちなみにのverなんかは以下でのおはなし

  • rails (3.2.7)
  • delayed_job (3.0.3)
  • delayed_job_active_record (0.3.2)

スマートにやる方法がわかんなかったので、わりと無理やりな。
ちなみにdelayed_jobにActiveRecord使用時のおはなし。

まず、delayed_jobsテーブルにmax_attemptsを追加。

rails g でサクっと。

bundle exec rails g migration add_max_attempts_to_delayed_jobs max_attempts:integer

こんなの↓ができる。

class AddMaxAttemptsToDelayedJobs < ActiveRecord::Migration
  def change
    add_column :delayed_jobs, :max_attempts, :integer
  end
end

migrateで適用。ドッコイショー

bundle exec rake db:migrate

んで、DB上のmax_attemptsにsetしたりgetしたりできるようにする。

initializers/delayed_job.rbあたりに

if defined?(Delayed::Backend::ActiveRecord::Job)
  module JobWithMaxAttemptsAttribute
    def self.included(base)
      base.class_eval do
        attr_accessible :max_attempts
        alias_method_chain :max_attempts, :attribute
      end
    end
    def max_attempts_with_attribute
      self[:max_attempts] || max_attempts_without_attribute
    end
  end
  Delayed::Backend::ActiveRecord::Job.send(:include, JobWithMaxAttemptsAttribute)
end

module名やらメソッド名は超テキトー。英語力ないですしおすし。

ほいでdelay実行時に

delayの引数でキーmax_attemptsにお望みの再試行回数を入れる。

HogeMailer.delay(max_attempts: 1).fuga(record)

指定しなかったりnilだったらデフォの回数になるはず。

PAGETOP
PAGETOP
PAGETOP

Comments (14)

Structure: For pretty much every last different Louis Vuitton backpack that could be revealed within the markets, yow will discover some sort of same in principle synthetic version.
ありませ

[2013/04/25 (木) 13:00]

Until you get hold of what you may were definitely corresponding, really don’t pay off! If ever the postal provider likes anyone to pay off earlier than allowing you to check out your handmade jewelry, turn down any plan!
りませ

[2013/04/25 (木) 13:05]


素晴らしい、私はあなたが書いた記事を投稿!

[2013/05/06 (月) 10:30]

書いた記事を投稿!

[2013/05/08 (水) 15:56]

これは、すべての情報が非常に明確に与えられている、非常に有益な記事だ。

[2014/05/14 (水) 17:15]

指定されたすべての情報は、これは非常に真の記事であることが非常に明確である。

[2014/09/24 (水) 16:09]

rchase sorbet; climbers even more magical role to protect MM grounds carrying MM left cross right cross over the bushes and small trees,

[2015/08/13 (木) 16:10]

プロジェクトのdirを適当につくってGemfileを作成。あとgit initもしとこう。

[2015/09/16 (水) 12:56]

かつて2015年のバーゼルのシャネル激安時計展初めて見得、

シャネルの超薄自動的にの上で鎖陀はずみ車腕時計、
今年プラチナの金の上着をはおって、

そのデザインはアイデアを高く備えて、
シャネル激安http://www.cctoh.com/

シャネルバッグ、腕時計、財布、靴、ピアス、眼鏡

超薄は表して殻のシャネル中で時計の歴史、
上で最も偉大な発明の中の一つを埋蔵していて。

[2015/11/23 (月) 00:36]

Nice Articles. My thanks for doing such a wonderful report. I will return here to find out more and recommend my neighbors about your website.

[2015/11/23 (月) 17:38]

bundle exec rails g migration add_max_attempts_to_delayed_jobs max_attempts:integer

[2016/01/06 (水) 17:40]

画面中央にこのボックスが表示されるサンプルで、ポップアップされたウィンドウ内でスクロールができるようにしたいのですが、どうしたらよいものか、と困っております。

[2016/01/07 (木) 11:15]

アイブ氏は前に自分のものを読んで、あなたはあまりにも素晴らしい。

[2016/01/15 (金) 17:38]

動かしたよメモ。動かしたよメモ。

[2016/07/08 (金) 09:33]
PAGETOP

Comment Form

PAGETOP

Trackbacks (0)

トラックバックはありません。

PAGETOP

Trackback URL

PAGETOP

Search