-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[review] EventBridge Scheduler の command に bundle exec を追加しないオプション #51
[review] EventBridge Scheduler の command に bundle exec を追加しないオプション #51
Conversation
@@ -12,12 +12,13 @@ class EventBridgeSchedule | |||
|
|||
attr_reader :name | |||
|
|||
def initialize(name, cron, command, container_type, storage_size_gb) | |||
def initialize(name, cron, command, container_type, storage_size_gb, without_bundle_exec: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好み
↓みたいな命名のほうがよくあるパターンでしっくり来ました。(コード検索結果は5 vs 1.3k)
def initialize(name, cron, command, container_type, storage_size_gb, without_bundle_exec: false) | |
def initialize(name, cron, command, container_type, storage_size_gb, use_bundler: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よさそう
あと、引数を増やすのではなくて command 引数に文字列ではなく Hash で { value: 'hoge', use_bundler: false }
って渡す手段もありそうだと思ったりしました
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hashの場合も必須のキーが足りない場合にちゃんと分かりやすいエラー出せればどちらでも良さそうですね!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copilot svc exec
で実行するがゆえに、エラー通知するのが極端に難しい、、、
わかりやすくオプション引数増やしたほうがよさそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copilot svc exec
で実行するがゆえに、エラー通知するのが極端に難しい、、、
エラー通知というか、あとでエラーのログ見た時に何が原因でエラーとなったのか一目で分かるようにしておいたほうが良さそうという意味でした。(このへんの途中で例外発生すればどこかにログは残るんですよね?)
例えば必須のオプションが未設定の場合にも処理がどんどん進んで、よく分からない箇所でエラーとかだと調査に時間泥棒されそうだなーみたいな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例外発生したら bugsnag にくるはずですね
Hash 指定できるようにするなら、その中身が適切かどうか、そうでなければ何が不足してるのかわかるようなメッセージで例外だせばよさそうってことでしたか
schedules.to_h.map { |name, info| | ||
EventBridgeSchedule.new( | ||
name.to_s, info[:cron], info[:command], info[:container_type], info[:storage_size_gb], | ||
without_bundle_exec: info[:without_bundle_exec] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好み
ここまで増えてくると他も全てキーワード引数のほうが分かりやすい気も、、w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ですよねー
@name = name | ||
@cron = cron | ||
@command = command | ||
@container_type = container_type || 'small' | ||
@storage_size_gb = storage_size_gb # sizeInGiB | ||
@without_bundle_exec = without_bundle_exec.presence | ||
@use_bundler = use_bundler.presence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presenceは何のためですか?(不要そうに見えました)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
空文字が入ると true になるから、だったのですが、デフォルト true になったので不要そう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ああなるほどー。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use_bundler: nil
と指定されると use_bundler? => false になってしまうので use_bundler.presence || true
にしておかないといけなさそうでした
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
いや、false.presence => nil になるからだめだ
convert メソッドの方を修正したほうがよさそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おかしな設定された場合の挙動は、他のrails標準のyamlと挙動が揃っていればそれで十分じゃないかなーとも思いました。
例えばdatabase.ymlのadvisory_locksとかtrue, falseでの設定だけど、他の値が入れられた場合はどうなるんだろう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この initialize メソッドを直接呼ぶことはいまのところ想定できないし、aki さんが提案してくれたように convert メソッドで info.slice してキーワード引数を適切に指定してもらえばよさそうだなって思いました
boolean と presence でなんか混乱してしまったから、余計な処理を増やすとドツボにハマりそう。。。
schedules.to_h.map { |name, info| | ||
EventBridgeSchedule.new( | ||
name.to_s, info[:cron], info[:command], info[:container_type], info[:storage_size_gb], | ||
use_bundler: info[:use_bundler].nil? ? true : info[:use_bundler] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全部キーワード引数にしてしまえば、設定がない場合はキーワード引数の初期値任せとかも簡単に出来そう?(これだと初期値のtrueが二重管理されてしまってるなーと)
EventBridgeSchedule.new(name: name.to_s, **info.slice(:cron, :command, :container_type, :storage_size_gb, :use_bundler))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slice して渡すのいいですね!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今回の変更と無関係だけどついでに気になったのでコメントしておくと、storage_size_gbも任意のはずなのでinitializeの引数でちゃんと任意だということが分かるほうが良さそうだなと思いました!(あとから見た時どこまで必須でどこまで任意か一目で分かるほうが嬉しそう)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
↑のようにリファクタしてめちゃスッキリしました!ありがとうございますー!
@@ -12,12 +12,13 @@ class EventBridgeSchedule | |||
|
|||
attr_reader :name | |||
|
|||
def initialize(name, cron, command, container_type, storage_size_gb) | |||
def initialize(name:, cron:, command:, container_type: 'small', storage_size_gb: nil, use_bundler: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
今はこのままでいいと思いつつ、今後引数さらに増えるようならオプショナルな引数は↓みたいにまとめてしまうという方法もありですねー。
def initialize(name:, cron:, command:, **options)
@container_type = options.fetch(:container_type, 'small')
@storage_size_gb = options.fetch(:storage_size_gb, nil)
end
…-with-array [review] EventBridge Scheduler の run task command を配列で指定できるように
No description provided.