taskinator 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f8f0c88f1bf0ade876afc82c451b310064d0e07
4
- data.tar.gz: 920e74b55fef2506b49e9a2ec21389cf646ef72d
3
+ metadata.gz: 1cac7446426c45fc14b6cc0dee7620874e322fa2
4
+ data.tar.gz: 7dd667765ef5e6a139b99ea03604aef198f80130
5
5
  SHA512:
6
- metadata.gz: dd62e9056ce98cf2e78aa51dd95a3ce24d14e0fb894bfc699afca93950bca9c54d9c39a9259dc180a10ca7ac97a1bf76fa133cd38058833e38a5ee114920d0e1
7
- data.tar.gz: 9dec75c348b5a66f55526b15fe7f04e76992e574d066667134bab276c27694ae60a29bce396b1aa668ef367b6ec491ef8276034984dca769f782096ab6681a6f
6
+ metadata.gz: de3cc2b3dd447ed10b1662cca01ea0398c35c375466ee3a55b3ed67eefc28cd1a8d5888e56f50258bc2027f7ea4f8462ba0bc52cac2d2f242dbd56b46b7548b4
7
+ data.tar.gz: c98d31d5968ecfc7289831b327a1fd00bb9be75c0206304f3d8aed6b38fbf3ec4d3460b85b3cf439604ea2490095d8fee60280c27c43a18b71c6a9b3aa47d03c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- taskinator (0.3.9)
4
+ taskinator (0.3.10)
5
5
  builder (>= 3.2.2)
6
6
  connection_pool (>= 2.2.0)
7
7
  globalid (~> 0.3)
@@ -68,6 +68,15 @@ module Taskinator
68
68
  end
69
69
  end
70
70
 
71
+ def to_xml
72
+ builder = ::Builder::XmlMarkup.new
73
+ builder.instruct!
74
+ builder.tag!('process', :key => self.key) do |xml|
75
+ XmlSerializationVisitor.new(xml, self).visit
76
+ end
77
+ builder
78
+ end
79
+
71
80
  # the persistence key
72
81
  def key
73
82
  @key ||= self.class.key_for(self.uuid)
@@ -262,7 +271,10 @@ module Taskinator
262
271
  tasks.each do |task|
263
272
  RedisSerializationVisitor.new(@conn, task, @base_visitor).visit
264
273
  @conn.rpush "#{@key}:tasks", task.uuid
265
- @base_visitor.incr_task_count unless task.is_a?(Task::SubProcess)
274
+ unless task.is_a?(Task::SubProcess)
275
+ incr_task_count unless self == @base_visitor
276
+ @base_visitor.incr_task_count
277
+ end
266
278
  end
267
279
  end
268
280
 
@@ -315,6 +327,118 @@ module Taskinator
315
327
  end
316
328
  end
317
329
 
330
+ class XmlSerializationVisitor < Taskinator::Visitor::Base
331
+
332
+ #
333
+ # the redis connection is passed in since it is
334
+ # in the multi statement mode in order to produce
335
+ # one roundtrip to the redis server
336
+ #
337
+
338
+ attr_reader :builder
339
+ attr_reader :instance
340
+
341
+ def initialize(builder, instance, base_visitor=self)
342
+ @builder = builder
343
+ @instance = instance
344
+ @key = instance.key
345
+ @root = base_visitor.instance
346
+ @base_visitor = base_visitor
347
+ @task_count = 0
348
+ end
349
+
350
+ # the starting point for serializing the instance
351
+ def visit
352
+ @attributes = []
353
+ @attributes << [:type, @instance.class.name]
354
+ @attributes << [:process_uuid, @root.uuid]
355
+ @attributes << [:state, :initial]
356
+
357
+ @instance.accept(self)
358
+
359
+ @attributes << [:task_count, @task_count]
360
+
361
+ @attributes.each do |(name, value)|
362
+ builder.tag!('attribute', name => value)
363
+ end
364
+
365
+ self
366
+ end
367
+
368
+ def visit_process(attribute)
369
+ process = @instance.send(attribute)
370
+ if process
371
+ @attributes << [attribute, process.uuid]
372
+
373
+ builder.tag!('process', :key => process.key) do |xml|
374
+ XmlSerializationVisitor.new(xml, process, @base_visitor).visit
375
+ end
376
+ end
377
+ end
378
+
379
+ def visit_tasks(tasks)
380
+ builder.tag!('tasks') do |xml|
381
+ tasks.each do |task|
382
+ xml.tag!('task', :key => task.key) do |xml2|
383
+ XmlSerializationVisitor.new(xml2, task, @base_visitor).visit
384
+ unless task.is_a?(Task::SubProcess)
385
+ incr_task_count unless self == @base_visitor
386
+ @base_visitor.incr_task_count
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end
392
+
393
+ def visit_attribute(attribute)
394
+ value = @instance.send(attribute)
395
+ @attributes << [attribute, value] if value
396
+ end
397
+
398
+ def visit_attribute_time(attribute)
399
+ visit_attribute(attribute)
400
+ end
401
+
402
+ def visit_attribute_enum(attribute, type)
403
+ visit_attribute(attribute)
404
+ end
405
+
406
+ def visit_process_reference(attribute)
407
+ process = @instance.send(attribute)
408
+ @attributes << [attribute, process.uuid] if process
409
+ end
410
+
411
+ def visit_task_reference(attribute)
412
+ task = @instance.send(attribute)
413
+ @attributes << [attribute, task.uuid] if task
414
+ end
415
+
416
+ def visit_type(attribute)
417
+ type = @instance.send(attribute)
418
+ @attributes << [attribute, type.name] if type
419
+ end
420
+
421
+ def visit_args(attribute)
422
+ values = @instance.send(attribute)
423
+ yaml = Taskinator::Persistence.serialize(values)
424
+
425
+ # greater than 2 MB?
426
+ if (yaml.bytesize / (1024.0**2)) > 2
427
+ Taskinator.logger.warn("Large argument data detected for '#{self.to_s}'. Consider using intrinsic types instead, or try to reduce the amount of data provided.")
428
+ end
429
+
430
+ @attributes << [attribute, yaml]
431
+ end
432
+
433
+ def task_count
434
+ @task_count
435
+ end
436
+
437
+ def incr_task_count
438
+ @task_count += 1
439
+ end
440
+ end
441
+
318
442
  class RedisDeserializationVisitor < Taskinator::Visitor::Base
319
443
 
320
444
  #
@@ -41,6 +41,7 @@ module Taskinator
41
41
  @queue = options.delete(:queue)
42
42
  @created_at = Time.now.utc
43
43
  @updated_at = created_at
44
+ @current_state = :initial
44
45
  end
45
46
 
46
47
  def parent=(value)
@@ -39,6 +39,7 @@ module Taskinator
39
39
  @queue = options.delete(:queue)
40
40
  @created_at = Time.now.utc
41
41
  @updated_at = created_at
42
+ @current_state = :initial
42
43
  end
43
44
 
44
45
  def accept(visitor)
@@ -1,3 +1,3 @@
1
1
  module Taskinator
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
@@ -2,11 +2,11 @@ module Taskinator
2
2
  module Workflow
3
3
 
4
4
  def current_state
5
- # NB: don't memoize this value (i.e. re-read it each time)
6
- @current_state = load_workflow_state
5
+ @current_state ||= load_workflow_state
7
6
  end
8
7
 
9
8
  def current_state=(new_state)
9
+ return if new_state == @current_state
10
10
  @current_state = persist_workflow_state(new_state)
11
11
  end
12
12
 
@@ -210,6 +210,10 @@ describe Taskinator::Persistence, :redis => true do
210
210
  pending __FILE__
211
211
  end
212
212
 
213
+ describe "#to_xml" do
214
+ pending __FILE__
215
+ end
216
+
213
217
  describe "#key" do
214
218
  it {
215
219
  expect(subject.key).to match(/#{subject.uuid}/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taskinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Stefano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-12 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis