Skip to content

Instantly share code, notes, and snippets.

@jmettraux
Forked from netinlet/json_decode_error.rb
Created March 27, 2012 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmettraux/2219926 to your computer and use it in GitHub Desktop.
Save jmettraux/2219926 to your computer and use it in GitHub Desktop.
json decode error
rvm use 1.9.2-p290
source :rubygems
gem 'yajl-ruby', '1.0.0', :require => 'yajl'
gem 'ruote', :git => 'git://github.com/jmettraux/ruote.git'
gem 'ruote-sequel', :git => 'git://github.com/jmettraux/ruote-sequel.git'
gem 'pg'
gem 'sinatra'
GIT
remote: git://github.com/jmettraux/ruote-sequel.git
revision: b67adc8ac8099c70cef618f82fa740f07a51de5b
specs:
ruote-sequel (2.3.0)
ruote (>= 2.3.0)
sequel
GIT
remote: git://github.com/jmettraux/ruote.git
revision: dfbcf13e548418ade88c7300605c43a7a4ee20fb
specs:
ruote (2.3.0)
parslet (= 1.2.3)
rufus-cloche (>= 1.0.2)
rufus-dollar (>= 1.0.4)
rufus-json (>= 1.0.1)
rufus-mnemo (>= 1.2.2)
rufus-scheduler (>= 2.0.16)
rufus-treechecker (>= 1.0.8)
sourcify (= 0.5.0)
GEM
remote: http://rubygems.org/
specs:
blankslate (2.1.2.4)
file-tail (1.0.8)
tins (~> 0.3)
parslet (1.2.3)
blankslate (~> 2.0)
pg (0.13.2)
rack (1.4.1)
rack-protection (1.2.0)
rack
ruby2ruby (1.3.1)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
rufus-cloche (1.0.2)
rufus-json (>= 1.0.1)
rufus-dollar (1.0.4)
rufus-json (1.0.1)
rufus-mnemo (1.2.2)
rufus-scheduler (2.0.16)
tzinfo (>= 0.3.23)
rufus-treechecker (1.0.8)
ruby_parser (>= 2.0.5)
sequel (3.33.0)
sexp_processor (3.1.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sourcify (0.5.0)
file-tail (>= 1.0.5)
ruby2ruby (>= 1.2.5)
ruby_parser (>= 2.0.5)
sexp_processor (>= 3.0.5)
tilt (1.3.3)
tins (0.3.12)
tzinfo (0.3.32)
yajl-ruby (1.0.0)
PLATFORMS
ruby
DEPENDENCIES
pg
ruote!
ruote-sequel!
sinatra
yajl-ruby (= 1.0.0)
require 'rufus-json/automatic'
require 'ruote'
require 'pg'
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('postgres://localhost/ruote_test')
Ruote::Sequel.create_table(SEQUEL_CONNECTION, false)
RUOTE_STORAGE = Ruote::Sequel::Storage.new(SEQUEL_CONNECTION, {})
p [ :count, SEQUEL_CONNECTION[:documents].count ]
RUOTE_STORAGE.purge!
p [ :count, SEQUEL_CONNECTION[:documents].count ]
ENGINE = Ruote::Dashboard.new(Ruote::Worker.new(RUOTE_STORAGE))
## 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
class Case
attr_reader :id, :case_stage
def initialize
@id = (Time.now.to_f * 10000).to_i
@case_state = nil
end
def self.create!
self.new
end
def self.update_case_stage(id, value)
# nothing to do
end
end
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
stage1
stage2
stage3
end
module Ruote
class StorageHistory
def steps_by_process(wfid)
msgs = self.by_process(wfid).select{ |msg|
'dispatched' == msg['action']
}.sort_by { |msg|
msg['original_put_at']
}.map { |msg|
msg['participant_name']
}
end
end
end
require 'ruote/log/storage_history'
ENGINE.add_service('history', Ruote::StorageHistory)
#
# web resources (thanks to Sinatra)
#
require 'sinatra'
get '/start' do
kase = Case.create!
wfid = ENGINE.launch(STAGES_PDEF, :reference => kase.id)
"<a href='http://127.0.0.1:4567/history/#{wfid}'>history</a>"
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