Sha256: 07b22e9fc1e587f55ff62c045770e54e0f789bf088e746655512485e331f4d4a

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'pallets'

Pallets.configure do |c|
  c.backend_args = { url: 'redis://127.0.0.1:6379/13' }
end

class DoGroceries < Pallets::Workflow
  task :enter_shop
  task :get_shopping_cart => :enter_shop
  task :put_milk => :get_shopping_cart
  task :put_bread => :get_shopping_cart
  task :pay => [:put_milk, :put_bread]
  task :go_home => :pay
end

class EnterShop < Pallets::Task
  def run
    puts "Entering #{context['shop_name']}"
    raise 'Cannot enter shop!' if (context['i'].to_i % 10).zero?
  end
end

class GetShoppingCart < Pallets::Task
  def run
    puts "Where's that 50 cent coin??"
    context['need_to_return_coin'] = true
  end
end

class PutMilk < Pallets::Task
  def run
    puts "Whole or half? Hmm..."
    sleep 1
  end
end

class PutBread < Pallets::Task
  def run
    raise 'Out of bread!' if (context['i'].to_i % 30).zero?
    puts "Got the bread"
  end
end

class Pay < Pallets::Task
  def run
    puts "Paying by #{context['pay_by']}"
    sleep 2
    raise 'Payment failed!' if (context['i'].to_i % 100).zero?
  end
end

class GoHome < Pallets::Task
  def run
    puts "Done!!"

    if context['need_to_return_coin']
      puts '...forgot to get my coin back...'
    end
  end
end

1_000.times { |i| DoGroceries.new(shop_name: 'Pallet Shop', pay_by: :card, i: i).run }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pallets-0.3.0 examples/do_groceries.rb