Skip to content

Instantly share code, notes, and snippets.

@jasonvasquez

jasonvasquez/test_case.rb Secret

Created May 7, 2012
Embed
What would you like to do?
Test Case
#!/usr/bin/env ruby
require 'bundler/setup'
require 'json'
require 'ruote'
require 'ruote/storage/fs_storage'
require 'pry'
class Notifier
include Ruote::LocalParticipant
def on_workitem
puts "I'm the notifier, message_type: #{workitem.params['message_type']}"
reply
end
def on_cancel
end
end
RUOTE_STORAGE = Ruote::FsStorage.new('ruote_data')
ENGINE = Ruote::Engine.new(Ruote::Worker.new(RUOTE_STORAGE))
ENGINE.context.logger.noisy = true
ENGINE.register do
participant :notifier, Notifier
catchall
end
pdef = Ruote.process_definition :name => 'report', :revision => '1.0' do
sequence 'main_flow' do
echo "Beginning main flow"
cursor 'draft_state' do
echo "Beginning draft_state, status: ${f:status}"
form_submitter :timers => '1s: form_draft_reminder, 4s: form_draft_reminder, 12s: cancel_draft_submission'
rewind :if => "${f:status} != 'submitted'"
notifier :message_type => 'form_submitted'
end
echo "submission closed!"
end
define 'form_draft_reminder' do
echo "Beginning form_draft_reminder"
notifier :message_type => 'draft_reminder'
end
define 'cancel_draft_submission' do
echo "Beginning cancel_draft_submission"
sequence do
notifier :message_type => 'draft_timeout'
kill_process
end
end
end
wfid = ENGINE.launch(pdef, {'status' => 'draft'})
sleep 2
p = ENGINE.process(wfid)
p.workitems.each do |wi|
next if wi.participant_name.eql?('notifier')
wi.set_field('status', 'submitted')
ENGINE.storage_participant.proceed(wi)
end
ENGINE.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.