Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#-- | ||
# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
# Made in Japan. | ||
#++ | ||
|
||
|
||
module Ruote | ||
|
||
# | ||
# Logs the ruote engine history to the storage underlying the worker. | ||
# | ||
# Warning : don't use this history implementation when the storage is | ||
# HashStorage. It will fill up your memory... Keeping history for a | ||
# transient ruote is a bit overkill (IMHO). | ||
# | ||
class StorageHistory | ||
|
||
def initialize (context, options={}) | ||
|
||
@context = context | ||
@options = options | ||
|
||
if @context.worker | ||
|
||
# only care about logging if there is a worker present | ||
|
||
@context.storage.add_type('history') | ||
@context.worker.subscribe(:all, self) | ||
end | ||
end | ||
|
||
def by_process (wfid) | ||
|
||
@context.storage.get_many('history', /!#{wfid}$/) | ||
end | ||
alias :by_wfid :by_process | ||
|
||
# Returns an array [ most recent date, oldest date ] (Time instances). | ||
# | ||
def range | ||
|
||
# TODO : implement me | ||
end | ||
|
||
def by_date (date) | ||
|
||
# TODO : implement me | ||
end | ||
|
||
#def history_to_tree (wfid) | ||
# # (NOTE why not ?) | ||
#end | ||
|
||
# The history system doesn't implement purge! so that when purge! is called | ||
# on the engine, the history is not cleared. | ||
# | ||
# Call this *dangerous* clear! method to clean out any history file. | ||
# | ||
def clear! | ||
end | ||
|
||
# This is the method called by the workqueue. Incoming engine events | ||
# are 'processed' here. | ||
# | ||
def notify (msg) | ||
|
||
msg = msg.dup | ||
# a shallow copy is sufficient | ||
|
||
t = msg['_id'].split('-').last | ||
# '_id' => "#{$$}-#{Thread.current.object_id}-#{Time.now.to_f.to_s}" | ||
|
||
si = if fei = msg['fei'] | ||
Ruote::FlowExpressionId.to_storage_id(fei) | ||
else | ||
msg['wfid'] || 'no_wfid' | ||
end | ||
|
||
msg['original_id'] = msg['_id'] | ||
msg['_id'] = "#{t}!#{si}" | ||
msg['type'] = 'history' | ||
msg['original_put_at'] = msg['put_at'] | ||
msg.delete('_rev') | ||
|
||
@context.storage.put(msg) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
# | ||
# testing ruote | ||
# | ||
# Tue Jan 5 17:51:10 JST 2010 | ||
# | ||
|
||
require File.join(File.dirname(__FILE__), 'base') | ||
|
||
require 'ruote/log/fs_history' | ||
require 'ruote/part/no_op_participant' | ||
|
||
|
||
class FtStorageHistoryTest < Test::Unit::TestCase | ||
include FunctionalBase | ||
|
||
def test_launch | ||
|
||
pdef = Ruote.process_definition do | ||
alpha | ||
echo 'done.' | ||
end | ||
|
||
history = @engine.add_service( | ||
'history', 'ruote/log/storage_history', 'Ruote::StorageHistory') | ||
|
||
@engine.register_participant :alpha, Ruote::NoOpParticipant | ||
|
||
#noisy | ||
|
||
wfid0 = assert_trace(pdef, "done.") | ||
wfid1 = assert_trace(pdef, "done.\ndone.") | ||
|
||
sleep 0.100 | ||
|
||
assert_equal 17, @engine.storage.get_many('history').size | ||
|
||
h = @engine.context.history.by_process(wfid0) | ||
#h.each { |r| p r } | ||
assert_equal 8, h.size | ||
|
||
# testing record.to_h | ||
|
||
h = @engine.context.history.by_process(wfid1) | ||
#h.each { |r| p r } | ||
assert_equal 8, h.size | ||
|
||
history.clear! | ||
|
||
assert_equal 0, @engine.storage.get_many('history') | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters