eventus 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Eventus
22
22
  def populate(stream)
23
23
  @stream = stream
24
24
  stream.committed_events.each do |event|
25
- apply_change event[:name], event[:body], false
25
+ apply_change event['name'], event['body'], false
26
26
  end
27
27
  end
28
28
 
@@ -9,6 +9,7 @@ module Eventus
9
9
  end
10
10
 
11
11
  def dispatch(events)
12
+ Eventus.logger.info "Dispatching #{events.length} events"
12
13
  events.each do |e|
13
14
  @action.call(e)
14
15
  @persistence.mark_dispatched e
@@ -10,6 +10,7 @@ module Eventus
10
10
  @serializer = options.delete(:serializer) || Eventus::Serializers::Marshal
11
11
  queue_con = build_connection(:path => options.delete(:queue_path) || '*')
12
12
  con = build_connection(options)
13
+ Eventus.logger.info "Opening db: #{con}, queue: #{queue_con}"
13
14
  raise Eventus::ConnectionError unless @db.open(con) && @queue.open(queue_con)
14
15
  end
15
16
 
@@ -26,6 +27,7 @@ module Eventus
26
27
  end
27
28
 
28
29
  def load(id, min = nil)
30
+ Eventus.logger.debug "Loading stream: #{id}"
29
31
  pid = pack_hex(id)
30
32
  keys = @db.match_prefix(pid)
31
33
 
@@ -45,10 +47,12 @@ module Eventus
45
47
  obj = @serializer.deserialize(value)
46
48
  events << obj
47
49
  end
50
+ Eventus.logger.info "#{events.length} undispatched events loaded"
48
51
  events
49
52
  end
50
53
 
51
54
  def mark_dispatched(stream_id, sequence)
55
+ Eventus.logger.debug "Marking #{stream_id}_#{sequence} dispatched"
52
56
  key = build_key(pack_hex(stream_id), sequence)
53
57
  @queue.remove(key)
54
58
  end
@@ -25,11 +25,13 @@ module Eventus
25
25
  e['sid'] = @id
26
26
  e['sequence'] = i
27
27
  end
28
+ Eventus::logger.debug "Committing #{@uncommitted_events.length} events to #{@id}"
28
29
  @persistence.commit @uncommitted_events
29
30
  load_events @uncommitted_events
30
31
  @dispatcher.dispatch @uncommitted_events if @dispatcher
31
32
  @uncommitted_events.clear
32
33
  rescue ConcurrencyError => e
34
+ Eventus.logger.info "ConcurrencyError, loading new events for: #{id}"
33
35
  load_events @persistence.load(id, version + 1)
34
36
  raise e
35
37
  end
@@ -1,3 +1,3 @@
1
1
  module Eventus
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/eventus.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  module Eventus
2
4
  autoload :Serializers, 'eventus/serializers'
3
5
  autoload :AggregateRoot, 'eventus/aggregate_root'
@@ -22,6 +24,17 @@ module Eventus
22
24
  def dispatcher=(val)
23
25
  @dispatcher = val
24
26
  end
27
+
28
+ def logger
29
+ return @logger if @logger
30
+ @logger ||= Logger.new(STDOUT)
31
+ @logger.level = Logger::WARN
32
+ @logger
33
+ end
34
+
35
+ def logger=(val)
36
+ @logger = val
37
+ end
25
38
  end
26
39
  end
27
40
 
@@ -30,7 +30,7 @@ describe Eventus::AggregateRoot do
30
30
  describe "when events exist" do
31
31
  before do
32
32
  persistence.should_receive(:load).with('abc').and_return(events)
33
- events << {:name => 'dino', :body => {}}
33
+ events << {'name' => 'dino', 'body' => {}}
34
34
  end
35
35
 
36
36
  it "should apply the event" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000Z
12
+ date: 2012-01-16 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: An Event Store
15
15
  email:
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  segments:
59
59
  - 0
60
- hash: 3251011933680470651
60
+ hash: 2674942126495806471
61
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  segments:
68
68
  - 0
69
- hash: 3251011933680470651
69
+ hash: 2674942126495806471
70
70
  requirements: []
71
71
  rubyforge_project: eventus
72
72
  rubygems_version: 1.8.13