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
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Remix on Hono on Cloudflare Workers
yusukebe
1
290
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
ヤプリ新卒SREの オンボーディング
masaki12
0
130
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
670
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Building Your Own Lightsaber
phodgson
103
6.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Visualization
eitanlees
145
15k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Producing Creativity
orderedlist
PRO
341
39k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Code Review Best Practice
trishagee
64
17k
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 ʹ͠ͳ͍͍ͯ͘Μ͡Όͳ͍ʁ
՝ʹΞϓϩʔν͢Δ •ίʔυͷ͠͞ͱϥΠϒϥϦͷՁؔͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…
·͍ͣͪ࢝͘͞ΊΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠