ruote-dm 2.1.9 → 2.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,12 @@
2
2
  = ruote-dm - CHANGELOG.txt
3
3
 
4
4
 
5
+ == ruote-dm 2.1.10 released 2010/06/15
6
+
7
+ - :ide key, :length => 255 for MySQL (thanks irfn)
8
+ - _rev now starting at 1 (instead of 0)
9
+
10
+
5
11
  == ruote-dm 2.1.9 released 2010/03/24
6
12
 
7
13
  - storage participant queries with more than 1 field are now possible
data/CREDITS.txt CHANGED
@@ -9,11 +9,12 @@
9
9
 
10
10
  == contributors
11
11
 
12
+ - irfn (debugging on MySQL)
12
13
  - asm (many bug reports)
13
14
  - Kenneth Kalmer (http://www.opensourcery.co.za/)
14
15
 
15
16
 
16
17
  == many thanks to
17
18
 
18
- - the DataMapper team
19
+ - the DataMapper authors and contributors
19
20
 
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2001-2009, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.rdoc CHANGED
@@ -6,7 +6,29 @@ ruote 2.1 extension for DataMapper (dm) persistence
6
6
 
7
7
  == usage
8
8
 
9
- well...
9
+ This is how a ruote engine is setup with a ruote-dm storage (postgres) and a worker :
10
+
11
+ require 'rubygems'
12
+ require 'json' # gem install json
13
+ require 'ruote'
14
+ require 'ruote-dm' # gem install ruote-dm
15
+
16
+ #DataMapper.setup(:default, 'sqlite3::memory:')
17
+ #DataMapper.setup(:default, 'sqlite3:ruote_test.db')
18
+ DataMapper.setup(:default, 'postgres://localhost/ruote_test')
19
+
20
+ engine = Ruote::Engine.new(
21
+ Ruote::Worker.new(
22
+ Ruote::Dm::DmStorage.new(:default)))
23
+
24
+ # ...
25
+
26
+ To create the tables in the database :
27
+
28
+ Ruote::Dm::Document.auto_migrate!
29
+
30
+
31
+ Tested with dm 0.9.2 and dm 1.0.0, with the postgresql and the msyql adapters.
10
32
 
11
33
 
12
34
  == running tests
data/TODO.txt CHANGED
@@ -1,9 +1,15 @@
1
1
 
2
2
  [o] [test/functional/ft_20_storage_participant.rb:176]: <1> expected but was <4>
3
3
  not on ruby 1.9.1, but on ruby 1.8.7p72
4
+ [o] msgs / schedules : simplify like ruote-redis did
5
+ [o] `--> init _rev at 1 (like ruote-redis)
6
+ [o] `--> then investigate ct_X weaknesses (transactions ?)
7
+ [o] `--> then investigate ct_X weaknesses
4
8
 
5
9
  [ ] storage : control #save result
6
10
  [ ] examine indices (index) (participant_name ?) perf perf perf
7
11
 
8
- [ ] investigate ct_0_ weakness
12
+ [ ] write example on how to use active-record to "read" workitems
13
+
14
+ [ ] crunner.sh 2 weakness
9
15
 
@@ -30,20 +30,44 @@ require 'ruote/dm/version'
30
30
  module Ruote
31
31
  module Dm
32
32
 
33
+ #
34
+ # All the ruote data is stored in a single ruote_dm_document table.
35
+ #
36
+ # The doc/data itself is stored in the 'doc' column, as JSON.
37
+ #
38
+ # Yajl-ruby is recommended for fast {de|en}coding with JSON.
39
+ #
33
40
  class Document
34
41
  include DataMapper::Resource
35
42
 
36
- property :ide, String, :key => true, :length => 2048, :required => true
43
+ property :ide, String, :key => true, :length => 255, :required => true
37
44
  property :rev, Integer, :key => true, :required => true
38
45
  property :typ, String, :key => true, :required => true
39
46
  property :doc, Text, :length => 2**32 - 1, :required => true, :lazy => false
40
47
 
41
48
  property :participant_name, String, :length => 512
49
+
50
+ def to_h
51
+ Rufus::Json.decode(doc)
52
+ end
42
53
  end
43
54
 
44
55
  #
45
56
  # A datamapper-powered storage for ruote.
46
57
  #
58
+ # require 'rubygems'
59
+ # require 'json' # gem install json
60
+ # require 'ruote'
61
+ # require 'ruote-dm' # gem install ruote-dm
62
+ #
63
+ # #DataMapper.setup(:default, 'sqlite3::memory:')
64
+ # #DataMapper.setup(:default, 'sqlite3:ruote_test.db')
65
+ # DataMapper.setup(:default, 'postgres://localhost/ruote_test')
66
+ #
67
+ # engine = Ruote::Engine.new(
68
+ # Ruote::Worker.new(
69
+ # Ruote::Dm::DmStorage.new(:default)))
70
+ #
47
71
  class DmStorage
48
72
 
49
73
  include Ruote::StorageBase
@@ -58,48 +82,72 @@ module Dm
58
82
  put_configuration
59
83
  end
60
84
 
85
+ def put_msg (action, options)
86
+
87
+ # put_msg is a unique action, no need for all the complexity of put
88
+
89
+ DataMapper.repository(@repository) do
90
+
91
+ doc = prepare_msg_doc(action, options)
92
+
93
+ insert(doc, 1)
94
+ end
95
+
96
+ nil
97
+ end
98
+
99
+ def put_schedule (flavour, owner_fei, s, msg)
100
+
101
+ # put_schedule is a unique action, no need for all the complexity of put
102
+
103
+ doc = prepare_schedule_doc(flavour, owner_fei, s, msg)
104
+
105
+ return nil unless doc
106
+
107
+ DataMapper.repository(@repository) do
108
+
109
+ insert(doc, 1)
110
+
111
+ doc['_id']
112
+ end
113
+ end
114
+
61
115
  def put (doc, opts={})
62
116
 
63
117
  DataMapper.repository(@repository) do
64
118
 
65
- d = Document.first(:ide => doc['_id'], :typ => doc['type'])
119
+ current = do_get(doc['type'], doc['_id'])
66
120
 
67
- return Rufus::Json.decode(d.doc) if d && d.rev != doc['_rev']
121
+ rev = doc['_rev'].to_i
68
122
 
69
- if doc['_rev'].nil?
123
+ return true if current.nil? && rev > 0
124
+ return current.to_h if current && rev != current.rev
70
125
 
71
- d = Document.new(
72
- :ide => doc['_id'],
73
- :rev => 0,
74
- :typ => doc['type'],
75
- :doc => Rufus::Json.encode(doc.merge(
76
- '_rev' => 0, 'put_at' => Ruote.now_to_utc_s)),
77
- :participant_name => doc['participant_name']
78
- ).save
126
+ nrev = rev + 1
79
127
 
80
- doc['_rev'] = 0 if opts[:update_rev]
128
+ begin
81
129
 
82
- else
130
+ insert(doc, nrev)
131
+
132
+ current.destroy! if current
83
133
 
84
- return true unless d
134
+ doc['_rev'] = nrev if opts[:update_rev]
85
135
 
86
- d.rev = d.rev + 1
87
- d.doc = Rufus::Json.encode(doc.merge(
88
- '_rev' => d.rev, 'put_at' => Ruote.now_to_utc_s))
89
- d.save
136
+ return nil
90
137
 
91
- doc['_rev'] = d.rev if opts[:update_rev]
138
+ rescue DataObjects::IntegrityError => ie
139
+ #p :clash
92
140
  end
93
141
 
94
- nil
142
+ get(doc['type'], doc['_id'])
95
143
  end
96
144
  end
97
145
 
98
146
  def get (type, key)
99
147
 
100
148
  DataMapper.repository(@repository) do
101
- d = Document.first(:typ => type, :ide => key)
102
- d ? Rufus::Json.decode(d.doc) : nil
149
+ d = do_get(type, key)
150
+ d ? d.to_h : nil
103
151
  end
104
152
  end
105
153
 
@@ -109,14 +157,17 @@ module Dm
109
157
 
110
158
  DataMapper.repository(@repository) do
111
159
 
112
- d = Document.first(
113
- :typ => doc['type'], :ide => doc['_id'], :rev => doc['_rev'])
160
+ r = put(doc)
161
+
162
+ #p [ 0, true, doc['_id'], Thread.current.object_id.to_s[-3..-1] ] if r
114
163
 
115
- return true unless d
164
+ return true unless r.nil?
116
165
 
117
- d.destroy!
166
+ r = Document.all(:typ => doc['type'], :ide => doc['_id']).destroy!
118
167
 
119
- nil
168
+ #p [ 1, r ? nil : true, doc['_id'], Thread.current.object_id.to_s[-3..-1] ]
169
+
170
+ r ? nil : true
120
171
  end
121
172
  end
122
173
 
@@ -139,7 +190,7 @@ module Dm
139
190
  end
140
191
 
141
192
  DataMapper.repository(@repository) do
142
- Document.all(q).collect { |d| Rufus::Json.decode(d.doc) }
193
+ Document.all(q).collect { |d| d.to_h }
143
194
  end
144
195
  end
145
196
 
@@ -157,9 +208,15 @@ module Dm
157
208
  end
158
209
  end
159
210
 
160
- #def dump (type)
161
- # @dbs[type].dump
162
- #end
211
+ def dump (type)
212
+
213
+ s = "=== #{type} ===\n"
214
+
215
+ get_many(type).inject(s) do |s1, h|
216
+ s1 << " #{Ruote::FlowExpressionId.to_storage_id(h['fei'])}"
217
+ s1 << " => #{h['original_tree'].first} #{h['_rev']}\n"
218
+ end
219
+ end
163
220
 
164
221
  def shutdown
165
222
 
@@ -192,7 +249,7 @@ module Dm
192
249
  Document.all(
193
250
  :typ => type, :participant_name => participant_name
194
251
  ).collect { |d|
195
- Rufus::Json.decode(d.doc)
252
+ d.to_h
196
253
  }
197
254
  end
198
255
 
@@ -206,9 +263,7 @@ module Dm
206
263
  like.push(Rufus::Json.encode(value)) if value
207
264
  like.push('%')
208
265
 
209
- Document.all(:typ => type, :doc.like => like.join).collect { |d|
210
- Rufus::Json.decode(d.doc)
211
- }
266
+ Document.all(:typ => type, :doc.like => like.join).collect { |d| d.to_h }
212
267
  end
213
268
 
214
269
  def query_workitems (criteria)
@@ -235,13 +290,29 @@ module Dm
235
290
  ([ 'doc LIKE ?' ] * likes.size).join(' AND '), *likes
236
291
  ] unless likes.empty?
237
292
 
238
- Document.all(cr).collect { |d|
239
- Ruote::Workitem.new(Rufus::Json.decode(d.doc))
240
- }
293
+ Document.all(cr).collect { |d| d.to_h }
241
294
  end
242
295
 
243
296
  protected
244
297
 
298
+ def insert (doc, rev)
299
+
300
+ Document.new(
301
+ :ide => doc['_id'],
302
+ :rev => rev,
303
+ :typ => doc['type'],
304
+ :doc => Rufus::Json.encode(doc.merge(
305
+ '_rev' => rev,
306
+ 'put_at' => Ruote.now_to_utc_s)),
307
+ :participant_name => doc['participant_name']
308
+ ).save!
309
+ end
310
+
311
+ def do_get (type, key)
312
+
313
+ Document.first(:typ => type, :ide => key, :order => :rev.desc)
314
+ end
315
+
245
316
  # Don't put configuration if it's already in
246
317
  #
247
318
  # (avoid storages from trashing configuration...)
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ruote
3
3
  module Dm
4
- VERSION = '2.1.9'
4
+ VERSION = '2.1.10'
5
5
  end
6
6
  end
7
7
 
data/lib/ruote/dm.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require 'ruote/dm/storage'
3
+
data/ruote-dm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruote-dm}
8
- s.version = "2.1.9"
8
+ s.version = "2.1.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux"]
12
- s.date = %q{2010-03-24}
12
+ s.date = %q{2010-06-15}
13
13
  s.description = %q{datamapper storage for ruote (a ruby workflow engine)}
14
14
  s.email = %q{jmettraux@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -24,17 +24,18 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "TODO.txt",
26
26
  "lib/ruote-dm.rb",
27
+ "lib/ruote/dm.rb",
27
28
  "lib/ruote/dm/storage.rb",
28
29
  "lib/ruote/dm/version.rb",
29
30
  "ruote-dm.gemspec",
30
- "test/integration_connection.rb",
31
+ "test/functional_connection.rb",
31
32
  "test/test.rb"
32
33
  ]
33
34
  s.homepage = %q{http://github.com/jmettraux/ruote-dm}
34
35
  s.rdoc_options = ["--charset=UTF-8"]
35
36
  s.require_paths = ["lib"]
36
37
  s.rubyforge_project = %q{ruote}
37
- s.rubygems_version = %q{1.3.6}
38
+ s.rubygems_version = %q{1.3.5}
38
39
  s.summary = %q{datamapper storage for ruote (a ruby workflow engine)}
39
40
  s.test_files = [
40
41
  "test/test.rb"
@@ -45,20 +46,20 @@ Gem::Specification.new do |s|
45
46
  s.specification_version = 3
46
47
 
47
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
- s.add_runtime_dependency(%q<ruote>, [">= 2.1.9"])
49
+ s.add_runtime_dependency(%q<ruote>, [">= 2.1.10"])
49
50
  s.add_runtime_dependency(%q<dm-core>, [">= 0"])
50
51
  s.add_development_dependency(%q<yard>, [">= 0"])
51
52
  s.add_development_dependency(%q<rake>, [">= 0"])
52
53
  s.add_development_dependency(%q<jeweler>, [">= 0"])
53
54
  else
54
- s.add_dependency(%q<ruote>, [">= 2.1.9"])
55
+ s.add_dependency(%q<ruote>, [">= 2.1.10"])
55
56
  s.add_dependency(%q<dm-core>, [">= 0"])
56
57
  s.add_dependency(%q<yard>, [">= 0"])
57
58
  s.add_dependency(%q<rake>, [">= 0"])
58
59
  s.add_dependency(%q<jeweler>, [">= 0"])
59
60
  end
60
61
  else
61
- s.add_dependency(%q<ruote>, [">= 2.1.9"])
62
+ s.add_dependency(%q<ruote>, [">= 2.1.10"])
62
63
  s.add_dependency(%q<dm-core>, [">= 0"])
63
64
  s.add_dependency(%q<yard>, [">= 0"])
64
65
  s.add_dependency(%q<rake>, [">= 0"])
@@ -23,7 +23,7 @@ DataMapper.setup(:default, 'postgres://localhost/ruote_test')
23
23
  #DataMapper.setup(:default, 'sqlite3:ruote_test.db')
24
24
 
25
25
  #DataMapper.repository(:default) do
26
- # Ruote::Dm::Document.all.destroy!
26
+ # Ruote::Dm::Document.all.destroy! rescue nil
27
27
  # Ruote::Dm::Document.auto_upgrade!
28
28
  #end
29
29
 
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruote-dm
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 1
8
- - 9
9
- version: 2.1.9
4
+ version: 2.1.10
10
5
  platform: ruby
11
6
  authors:
12
7
  - John Mettraux
@@ -14,71 +9,59 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-03-24 00:00:00 +09:00
12
+ date: 2010-06-15 00:00:00 +09:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: ruote
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 1
30
- - 9
31
- version: 2.1.9
32
- type: :runtime
33
- version_requirements: *id001
23
+ version: 2.1.10
24
+ version:
34
25
  - !ruby/object:Gem::Dependency
35
26
  name: dm-core
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
38
30
  requirements:
39
31
  - - ">="
40
32
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
33
  version: "0"
44
- type: :runtime
45
- version_requirements: *id002
34
+ version:
46
35
  - !ruby/object:Gem::Dependency
47
36
  name: yard
48
- prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
50
40
  requirements:
51
41
  - - ">="
52
42
  - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
43
  version: "0"
56
- type: :development
57
- version_requirements: *id003
44
+ version:
58
45
  - !ruby/object:Gem::Dependency
59
46
  name: rake
60
- prerelease: false
61
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
62
50
  requirements:
63
51
  - - ">="
64
52
  - !ruby/object:Gem::Version
65
- segments:
66
- - 0
67
53
  version: "0"
68
- type: :development
69
- version_requirements: *id004
54
+ version:
70
55
  - !ruby/object:Gem::Dependency
71
56
  name: jeweler
72
- prerelease: false
73
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - ">="
76
62
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
63
  version: "0"
80
- type: :development
81
- version_requirements: *id005
64
+ version:
82
65
  description: datamapper storage for ruote (a ruby workflow engine)
83
66
  email: jmettraux@gmail.com
84
67
  executables: []
@@ -96,10 +79,11 @@ files:
96
79
  - Rakefile
97
80
  - TODO.txt
98
81
  - lib/ruote-dm.rb
82
+ - lib/ruote/dm.rb
99
83
  - lib/ruote/dm/storage.rb
100
84
  - lib/ruote/dm/version.rb
101
85
  - ruote-dm.gemspec
102
- - test/integration_connection.rb
86
+ - test/functional_connection.rb
103
87
  - test/test.rb
104
88
  has_rdoc: true
105
89
  homepage: http://github.com/jmettraux/ruote-dm
@@ -114,20 +98,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
98
  requirements:
115
99
  - - ">="
116
100
  - !ruby/object:Gem::Version
117
- segments:
118
- - 0
119
101
  version: "0"
102
+ version:
120
103
  required_rubygems_version: !ruby/object:Gem::Requirement
121
104
  requirements:
122
105
  - - ">="
123
106
  - !ruby/object:Gem::Version
124
- segments:
125
- - 0
126
107
  version: "0"
108
+ version:
127
109
  requirements: []
128
110
 
129
111
  rubyforge_project: ruote
130
- rubygems_version: 1.3.6
112
+ rubygems_version: 1.3.5
131
113
  signing_key:
132
114
  specification_version: 3
133
115
  summary: datamapper storage for ruote (a ruby workflow engine)