examples/do_groceries.rb in pallets-0.3.0 vs examples/do_groceries.rb in pallets-0.4.0
- old
+ new
@@ -1,24 +1,19 @@
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
+ task 'EnterShop'
+ task 'GetShoppingCart' => 'EnterShop'
+ task 'PutMilk' => 'GetShoppingCart'
+ task 'PutBread' => 'GetShoppingCart'
+ task 'Pay' => ['PutMilk', 'PutBread']
+ task 'GoHome' => '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
@@ -34,20 +29,18 @@
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
@@ -57,6 +50,6 @@
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 }
+DoGroceries.new(shop_name: 'Pallet Shop', pay_by: :card).run