fractaledmind / acidic_job

Elegant, resilient, durable workflows for Rails apps
https://fractaledmind.github.io/acidic_job/
MIT License
492 stars 10 forks source link

Iterable Steps #31

Closed fractaledmind closed 2 years ago

fractaledmind commented 2 years ago

Allow a step to define a collection from attr_accessors that should be iterated over and passed to the step method until fully processed

class WorkerWithForEachStep
  include Sidekiq::Worker
  include AcidicJob

  attr_reader :processed_items

  def initialize
    @processed_items = []
    super()
  end

  def perform
    with_acidity providing: { items: (1..10).to_a } do
      step :work_with_individual_item, for_each: :items
    end
  end

  def work_with_individual_item(item)
    @processed_items << item
  end
end

@julianrubisch: What do you think about the semantics?

julianrubisch commented 2 years ago

That looks intriguing!

Could you cook up an example where you'd process these iterable items over several steps?

fractaledmind commented 2 years ago

That looks intriguing!

Could you cook up an example where you'd process these iterable items over several steps?

Interesting idea. I need to tweak the implementation a bit, but I think I know how to make that possible. Will work on a PR with a text case tonight or tomorrow