Skip to content

Instantly share code, notes, and snippets.

@netinlet
Created March 26, 2012 21:39
Show Gist options
  • Save netinlet/2209952 to your computer and use it in GitHub Desktop.
Save netinlet/2209952 to your computer and use it in GitHub Desktop.
json decode error
# THE SQL for the Case object is above the Case Object
# To generate error
# to run: bundle exec ruby json_decode_error.rb
# http://localhost:4567/start
# Copy the WFID which is printed
# http://localhost:4567/history/:wfid
require 'rubygems'
require 'ruote'
require 'ruote/part/storage_participant'
require 'ruote/storage/fs_storage'
require 'yajl'
Rufus::Json.backend = :yajl
require 'pg'
require 'ruote-sequel'
require 'active_record'
require 'ruote-sequel'
connect_data = {
:adapter => 'postgresql',
:database => "bpm_reference_development",
:username => '', # your username
:password => '', # your password
:host => 'localhost',
:port => 5432
}
ActiveRecord::Base.configurations[:development] = connect_data
ActiveRecord::Base.include_root_in_json = true
ActiveRecord::Base.store_full_sti_class = true
ActiveSupport.use_standard_json_time_format = true
ActiveSupport.escape_html_entities_in_json = false
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[:development])
SEQUEL_CONNECTION = Sequel.connect(connect_data.merge(:adapter => "postgres"))
Ruote::Sequel.create_table(SEQUEL_CONNECTION, false) unless SEQUEL_CONNECTION.tables.include?(:documents)
RUOTE_STORAGE = Ruote::Sequel::Storage.new(SEQUEL_CONNECTION, {}) # documented option - # opts = { 'remote_definition_allowed' => true }
ENGINE = Ruote::Dashboard.new(Ruote::Worker.new(RUOTE_STORAGE))
ENGINE.register_participant :stage1 do |workitem|
Case.update_case_stage(workitem.fields['reference'], "stage1")
workitem.fields["case_result1"] = "Completed Stage 1"
end
ENGINE.register_participant :stage2 do |workitem|
Case.update_case_stage(workitem.fields['reference'], "stage2")
workitem.fields["case_result2"] = "Completed Stage 2"
end
ENGINE.register_participant :stage3 do |workitem|
Case.update_case_stage(workitem.fields['reference'], "stage3")
workitem.fields["case_result3"] = "Completed Stage 3"
end
STAGES_PDEF = Ruote.define do
sequence do
stage1
stage2
stage3
end
end
module Ruote
class StorageHistory
def steps_by_process(wfid)
# which ones were 'executed' - filters out items like setting up sequence and concurrence steps
all_expressions = self.by_process(wfid)
dispatched_expressions = all_expressions.select{|msg| 'dispatched' == msg["action"]}
# for all the msgessions, get the name and order by sorting by the original timestamp
dispatched_expressions.map do |msg|
[msg['participant_name'], msg["original_put_at"]]
end.sort{|a,b| a.last <=> b.last}.map{|exp| exp.first}
end
end
end
require 'ruote/log/storage_history'
ENGINE.add_service('history', Ruote::StorageHistory)
# CREATE TABLE cases (
# id SERIAL,
# case_state varchar(255)
# );
class Case < ActiveRecord::Base
def self.update_case_stage(reference, state)
kase = find(reference)
kase.update_attributes(:case_state => state)
kase
end
end
#
# web resources (thanks to Sinatra)
#
require 'cgi'
require 'sinatra'
require 'haml'
get '/start' do
kase = Case.create!
ENGINE.launch(STAGES_PDEF, :reference => kase.id)
end
get '/history/:wfid' do
ENGINE.history.steps_by_process(params[:wfid]).join(", ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment