Upgrade to Pro — share decks privately, control downloads, hide ads and more …

resque-scheduler

 resque-scheduler

Shinjuku.rb #43 発表資料
https://shinjukurb.connpass.com/event/44524/

Fumiaki MATSUSHIMA

November 30, 2016
Tweet

More Decks by Fumiaki MATSUSHIMA

Other Decks in Programming

Transcript

  1. (株)永和システムマネジメント
    @mtsmfm
    松島 史秋
    resque-scheduler

    View full-size slide

  2. 松島 史秋
    GitHub, Twitter
    @mtsmfm

    View full-size slide

  3. ポケモン S/M
    まっちまー
    フレコ
    1907-9185-9222

    View full-size slide

  4. resque-
    scheduler

    View full-size slide

  5. https://github.com/resque/resque-scheduler

    View full-size slide

  6. 大きく2つの
    機能

    View full-size slide

  7. - Delay
    - Schedule

    View full-size slide

  8. - Delay
    - 10分後に実行
    - Schedule
    - cron

    View full-size slide

  9. resque
    単体だと
    できない

    View full-size slide

  10. http://edgeguides.rubyonrails.org/active_job_basics.html#enqueue-the-job

    View full-size slide

  11. ActiveJob が
    やってくれたり
    してないかな

    View full-size slide

  12. Emoji provided free by Emoji One

    View full-size slide

  13. https://github.com/mtsmfm/
    resque-scheduler-example

    View full-size slide

  14. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque-
    scheduler.rb#L4

    View full-size slide

  15. 挙動が違う

    View full-size slide

  16. https://github.com/jmettraux/rufus-scheduler/blob/master/lib/rufus-
    scheduler.rb

    View full-size slide

  17. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/tasks.rb#L17-L18

    View full-size slide

  18. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/cli.rb#L117

    View full-size slide

  19. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L59-L70

    View full-size slide

  20. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/locking.rb#L65-L67

    View full-size slide

  21. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/locking.rb#L3-L50

    View full-size slide

  22. - master プロセスが落ちたときに複数回
    enqueue されないための機構
    - Redis の SETNX を使っている
    - Delayed job は SETNX で単純な十分
    - Scheduled job (cron っぽい方) は頻繁に
    master が変わると、マシンの時間がずれて
    いる場合に厳しい
    - (デフォルトだと) 3 分ごとに lock をとる
    - 2 回走ってもいいときや時間の同期がきっち
    りされているなら短くするとよい

    View full-size slide

  23. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L59-L70

    View full-size slide

  24. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L181-L190

    View full-size slide

  25. Schedule job
    は?

    View full-size slide

  26. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/locking.rb#L3-L50

    View full-size slide

  27. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler/locking.rb#L28-L30

    View full-size slide

  28. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L49-L53

    View full-size slide

  29. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L89-L104

    View full-size slide

  30. https://github.com/resque/resque-scheduler/blob/v4.3.0/lib/resque/
    scheduler.rb#L124-L163

    View full-size slide

  31. - 概要のわかる
    ドキュメント大事
    - resque-scheduler は
    多重実行されるくらいなら job
    が失われた方がいいという方

    - Lock 機構難しい

    View full-size slide