37 karma · joined Sep 30, 2015 (11y ago) · 28 submissions
1.
Give It Time(ismaelcelis.com ↗)
4 points · by ismaelct · 1y ago · discuss
2.
The Decide, Evolve, React Pattern in Ruby(ismaelcelis.com ↗)
6 points · by ismaelct · 2y ago · discuss
comment 2y ago · link · parent
comment 2y ago · link · parent
comment 2y ago · link · parent
I find that rule a bit arbitrary. For example, I have data-import pipelines where some steps are unique to each task, but some others are shared across tasks. Why does it matter whether the steps are defined in the same codebase or not?
comment 2y ago · link · parent
Indeed!https://github.com/hashicorp/vagrant/blob/main/lib/vagrant/a...
Yes, it's not a new pattern by any means, and there's many ways to "halt" the pipeline as you say. For example ActiveRecord stops callback chains if any callback throws ":halt".
Other examples are Redis.rb's pipelining API https://github.com/redis/redis-rb?tab=readme-ov-file#pipelin...
Or more generally any builder-style pattern that composes a set of operations for later execution, including again ActiveRecord's query chaining.
In my article I tried to show a specific implementation using the Railway pattern (where the result must only respond to "#continue?() => Boolean")
comment 2y ago · link · parent
I wonder if just using "throw :halt" (like in AR callbacks, to halt callback chains) or an Enumerator with "raise StopIteration" (which would work) would throw people off a bit less, just on account of those things being more familiar.
comment 2y ago · link · parent
I would further add that we should extend that thoughtfulness to the opinionated frameworks many of us rely on. They usually come with hundreds of complicated patterns baked in, and we "oversimplify our interfaces" to match the framework as a matter of course. All I'm saying is that committing to any mental model provided by a design pattern or framework has similar drawbacks. In this case, the mental model is "a big operation is a list of smaller operations in a chain". Use with caution.
> No need to think!
Not sure I agree with fully. If anything, I've found that I need to think harder about what constitutes a step in a workflow, what are the names of each stage, what concept they encapsulate. I can't just chuck everything into a god object or a deeply nested hierarchy tree somewhere.
But again I agree. Using this pattern I've definitely over-complicated or gone down the wrong path at times. I would say though that I found it easier to roll back and change direction when compared deeply nested object graphs, for example.
comment 2y ago · link · parent
I would add that the tagline says "when used thoughtlessly".
For example, I agree that using Result objects to reinvent exceptions is a bad idea. There's a reason they're called "exceptions". Error results should only be used for domain-level errors. ie. things that _your expect_ to go wrong in the domain.
Also note that in my article I use continue/halt, not Ok/Error. At the library level it's just a way to compose functions together with a mechanism to halt processing. Whether something halted execution because it was an error, or any other reason (ex. caching), is up to your app's semantics.
comment 2y ago · link · parent
Or ActiveRecord's query chaining?
ex. User.where(admin: true).joins(:account).order(id: :asc)
It's all versions of the same approach.
And yes all of the above _can_ complicate debugging, for sure. But so can most abstractions. Only use them if the specific problem they solve is bigger than the drawbacks.
comment 2y ago · link · parent
A pipeline is essentially this
steps = [ ->(r) { r }, ->(r) { r }, ->(r) { r }, ]
Wrap initial data in a common Value object
initial = Result.new(some_data)
Run the Result through the steps, in order
result = steps.reduce(initial) { |r, step| step.call(r) }
That's the pattern, really. A reduce operation.
Re. stack trace, it can add noise because you're iterating over steps instead of calling them procedurally one by one, and you may want to decorate steps (put steps inside steps) for encapsulation, caching, etc. but again no different than Rack.
comment 2y ago · link · parent
Pipeline steps are command objects (a pretty standard OO pattern), so they have a single entry point / public method. But they can still fully leverage any other OO pattern in their implementation. The more complex ones I use may instantiate other objects, pass messages between them, etc.
But the single-method #call API is what makes composition easy. See Rack, or any number of middleware-style designs, for other common uses of this in Ruby.
25.
Practical Railway-Oriented Pipelines in Ruby(ismaelcelis.com ↗)
67 points · by ismaelct · 2y ago · 66 comments