Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
circuit_switch: small start to create gem
Search
makicamel
October 10, 2021
Programming
3
2.5k
circuit_switch: small start to create gem
at 2021.10.10. Kaigi on Rails _2021_ new
makicamel
October 10, 2021
Tweet
Share
More Decks by makicamel
See All by makicamel
dRuby 入門者によるあなたの身近にあるdRuby 入門
makicamel
4
670
BulletmarkRepairer: auto corrector for N+1 queries
makicamel
10
6.5k
How to say goodbye to technical debt
makicamel
8
2.9k
Ganbaranai wo ganbaru
makicamel
5
4.4k
Automate the boring staff with Ruby
makicamel
1
940
Lets enjoy creating gems
makicamel
3
1.9k
Play with Rubys AST
makicamel
0
1.8k
Lets enjoy code reading
makicamel
5
890
OSS is great but not special
makicamel
7
7.7k
Other Decks in Programming
See All in Programming
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
受け取る人から提供する人になるということ
little_rubyist
0
230
イベント駆動で成長して委員会
happymana
1
320
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
C++でシェーダを書く
fadis
6
4.1k
最新TCAキャッチアップ
0si43
0
140
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
subpath importsで始めるモック生活
10tera
0
300
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building an army of robots
kneath
302
43k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
How STYLIGHT went responsive
nonsquared
95
5.2k
RailsConf 2023
tenderlove
29
900
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
DJSDVJU_TXJUDI ͍ͪ࢝͘͞ΊΔHFNͮ͘Γ 2021.10.10. Kaigi on Rails _2021_ new @makicamel
w!NBLJDBNFMݪສق w3VCZͱϏʔϧɹɹͱ͓ञ͕͖ w͖ͳ73ήʔϜ ࣗݾհ
࠷ۙࠔ͍ͬͯΔ͜ͱ ͓ࣄͰ
ো͕ଟ͍
•ӨڹൣғௐࠪΛ͕ΜΖ͏ •ϨϏϡʔΛ͕ΜΖ͏ •ࣗಈςετͷՃɾϝϯςΛ͕ΜΖ͏ •खಈςετΛ͕ΜΖ͏ •ΤϥʔࢹΛ͕ΜΖ͏ োΛىͨ͜͠ਓྨͷߟ͕͑ͪͳ͜ͱ ͬͱ ͬͱ ͬͱ ͬͱ
ͬͱ
͕ΜΓͨ͘ͳ͍
•͕ΜΔͱϛεΔ •͕ΜΓݸਓʹґଘ •͕ΜΔͱർΕΔ •͕ΜΔӬԕʹܧଓͰ͖ͳ͍ ͕ΜΓͨ͘ͳ͍
ΈͰͳΜͱ͔͍ͨ͠
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
•ϦϦʔεिʹ 1 ճ ˞ ˞োରԠΛআ͘
•ϦϦʔεिʹ 1 ճ •100ʙ200 Pull Requests •500ʙ1,000 commits •10Kʙ60K lines
˞ ϏοάόϯϦϦʔε ˞Ұ൪ݹ͘ػೳ͕ଟ͍ϞϊϦγοΫϦϙδτϦʹ͓͚Δɻଟ͘ͷଞϦϙδτϦͬͱԺ͔Ͱ͢ ˞োରԠΛআ͘ ˞
ϦϦʔείετ͕ߴͯ͘ো͕ଟ͘ɾେ͖͘ͳΓ͕ͪ ো͕ଟͯ͘ϦϦʔεසΛ্͛ΒΕͳ͍ ϏοάόϯϦϦʔε
ͱ͍͏Θ͚Ͱ
ͭͬͨ͘ NBLJDBNFMDJSDVJU@TXJUDI IUUQTHJUIVCDPNNBLJDBNFMDJSDVJU@TXJUI
circuit_switch
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
circuit_switch Γ͍ͨ͜ͱɿ ϦϦʔεසΛ͋͛Δ ˞ϦϦʔεස͍͋͛ͨͰ͢
circuit_switch Γ͍ͨ͜ͱɿ ίετʹΓ͢
circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end
CircuitSwitch.report(if: unexpected_happen)
circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end
circuit_switch •CircuitSwitch ͕։͍͍ͯΔ࣌ do_something_experimental ΛݺͿ •CircuitSwitch ͕ด͡ΒΕͨ࣌ call_existing_codes ΛݺͿ
if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end
circuit_switch •CircuitSwitch ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch •CircuitSwitch ͷ։ด݅ if CircuitSwitch.open?(reach_limit: 100) do_something_experimental else call_existing_codes
end نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch if CircuitSwitch.open?(if: current_user.testing?) do_something_experimental else call_existing_codes end •CircuitSwitch
ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch if CircuitSwitch.open?( close_if: Date.today > some_period ) do_something_experimental
else call_existing_codes end •CircuitSwitch ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch rake circuit_switch:terminate_to_run [/app/services/greetings_service:21 block in
validate] •CircuitSwitch ͷ։ด݅ if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch CircuitSwitch.report(if: unexpected_happen) •CircuitSwitch ͕։͍͍ͯΔ࣌ report ΛૹΔ •Slack
Bugsnag ͳͲҙͷϨϙʔτπʔϧΛࢦఆ •։ด݅ open? ͱྨࣅͷ݅Λࢦఆ
circuit_switch •ґଘϥΠϒϥϦ •ActiveRecord •࣮ߦߦʢcallerʣɾCircuitSwitch ͷ։ดঢ়ଶΛ DB ʹอଘ •ActiveJob •DB ߋ৽ɾϨϙʔτ
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍ •ͳ͍ͷ͕ΈͲ͜Ζʢʁʣ
ΈͲ͜Ζ •ԿมΘͬͨ͜ͱΛ͍ͬͯͳ͍ •Rails ͷίʔυ͕ॻ͚ͨΒॻ͚Δ •ࠓ͙͢ॻ͖࢝ΊΒΕΔ
ΈͲ͜Ζ •;ͭ͏ͷ Rails ΞϓϦ͕ґଘ͍ͯ͠ΔϥΠϒϥϦʹґଘ •ࠓ͙͢ಋೖͰ͖Δ
ͱ͜ΖͰ͓ؾ͖͔ͮͱࢥ͍·͕͢
Inspired by •Feature Toggles •CircuitBreaker 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM $JSDVJU#SFBLFSNBSUJOGPXMFSDPN
IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM
Feature Toggles •৽ػೳΛಛఆϢʔβʹ҆શɾ͔ʹఏڙ͢ΔͨΊͷΈ •ؔ࿈ɿDark Launch •🙅 େن feature ϒϥϯν্Ͱͷ։ൃ
🙆 master(main) ϒϥϯνʹ߹ྲྀͨ͠։ൃ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM
Feature Toggles •ΧφϦΞϦϦʔε •ϥϯμϜબग़ͷۃҰ෦ͷҰൠϢʔβʹػೳ։์༷ͯ͠ࢠݟ •A / B ςετ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN
IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM
CircuitBreaker •αʔόʹಛఆճҎ্ͷো͕ൃੜͨ࣌͠ʹ ϦΫΤετΛड͚͚ͣʹΤϥʔΛฦ͢Έ •োͷ࿈తͳൃੜΛ͙ •αʔό͕վળͨ͠ΒࣗಈͰ෮ؼ͢Δ $JSDVJU#SFBLFSNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM
Inspired by … ?
Inspired by … ? •ΠϯεύΠΞ͞Εͨͱ͍͏ʹΈ͕͠ΐ΅͍ •τάϧͷཧʹ͕͋Δ •ϒϨʔΧʔΛམͱ͕݅ͨͩ͢ͷճ •ࣗಈ෮ؼ͠ͳ͍ •DB ΞΫηεΛ͢ΔͷͰΦʔόʔϔου͕ੜ͡Δ
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
Ұूத •΄͍͠ͷʮίετʹΓͤΔʯΈ •ͱʹ͔͘ࠓ΄͍͠ ػೳ͚ͩΛ࣮ͯ͠ϦϦʔε
ॠൃྗ •ͱΓ͋͑ͣ΄͔ͬͨ͠ •ϨϏϡʔɾௐࠪɾςετίετ͕૿େ͍ͯ͠Δঢ়گΛվળ͍ͨ͠ •ݱͷࠓ͋Δ՝Λࠓ͙͢ղܾ͍ͨ͠ •Γͳ͍ࣝɾٕज़ͨ͘͞Μ͋Δ •४උ͕Ͱ͖Δ·Ͱͭͱ͋ͬͱ͍͏ؒʹ݄͕ա͗Δ
ॠൃྗ •MVP •Minimum Viable Product •࣮༻࠷খݶͷ •ఏڙ͠ͳ͕Β։ൃ͢Δ
Βͳ͍ཧ༝ •ͦ͏͔͠Εͳ͍ •ͦ͏Ͱͳ͍͔͠Εͳ͍ •OSS ʹ͓͚ͯ͠୭͔ͷʹཱ͔ͭ͠Εͳ͍ •OSS ʹ͠ͳ͍ཧ༝ͳ͍ ɹgem ʹ͠ͳ͍͍ͯ͘Μ͡Όͳ͍ʁ
՝ʹΞϓϩʔν͢Δ •ίʔυͷ͠͞ͱϥΠϒϥϦͷՁؔͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…
·͍ͣͪ࢝͘͞ΊΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠