Migrating with gradual type validations #167
viralpraxis
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Wouldn't |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After migrating ~100 legacy services to Actor I can say that the most annoying and error-prone aspect of the process was adding
type
validations. We'd like to have have these validations defined for everyinput
andoutput
(both for correctness and self-documenting), but in many cases it was hard to say if runtime-generated objects would satisfy type constraints. For example, forUser::Destroy
actor we'd do something likewhich is a correct actor unless we forget to apply
to_i
conversion somewhere in client code:Note that
User::Destroy
is parametrically polymorphic due to silent ActiveRecord conversions (i.e.find(...)
works both withString
andInteger
if numeric primary keys are used)So I've come up with some sort of gradual migration mechanism with the following implementation:
Actors utilize this feature like this:
In case of type mismatch in local environments an exception will be raised; in production it will be simply reporter and the actor will be executed just like there were no type validations.
NOTES:
SAFE_TYPE_VALIDATOR
generated lambdas should implicitly returntrue
in order to avoid type-check failrueArray.wrap
is an AS feature, use[*type_specification]
for rails-less environmentsBeta Was this translation helpful? Give feedback.
All reactions