codeclimate-kafka 0.4.0 → 0.5.0

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: 6342040b86ab69ae63452bf69bd757cf1ed9eb84
4
- data.tar.gz: 9baba0293728b2935925add35dade45019c0287d
3
+ metadata.gz: 0b27b99381c9938065fdab7f96159efec38b6e7a
4
+ data.tar.gz: 88c4167a50b8c5c3cbf3d04fef305392d8d3affb
5
5
  SHA512:
6
- metadata.gz: bb387152b82a3281fb94020d16904503cb38456bfd409c489c3c6f8ec409b2f8540e77df7b714070040f98c97a47ed15386e085a7ae915390c6254bda128c130
7
- data.tar.gz: ebadd12e34eec8f23ca262605dbfaecb87742b18caf35cb46cf599ae59cfd415f46145d13d88c7103aa73c7bb0bcc9b44c1ce39ce3ab3107f0820d442ce61363
6
+ metadata.gz: 48ebbe244d8ed041b034eca81dc4f4b3fd7c960300fa8a6370167a4075e79fbe1afa6ed919ec21b8011ebb3e0ddebbab07dfd0e60525eff1e491e6f9acf5ff94
7
+ data.tar.gz: b78c5337244a202ee3c056fd1b727981cc7fc90289d2955315c7ec4e2ea72b888c6da126f340e9c54321b9e1d4d961ac4cf6bbb735a1854be63b3031763fcf68
@@ -11,14 +11,14 @@ module CC
11
11
  partition: partition,
12
12
  )
13
13
 
14
- Kafka.logger.debug("offset: #{@offset.topic}/#{@offset.partition} #{@offset.current}")
14
+ Kafka.logger.debug("offset: #{@offset.topic}/#{@offset.partition} #{current_offset(@offset)}")
15
15
 
16
16
  @consumer = Poseidon::PartitionConsumer.consumer_for_partition(
17
17
  client_id,
18
18
  seed_brokers,
19
19
  @offset.topic,
20
20
  @offset.partition,
21
- @offset.current
21
+ current_offset(@offset)
22
22
  )
23
23
  end
24
24
 
@@ -46,6 +46,10 @@ module CC
46
46
 
47
47
  private
48
48
 
49
+ def current_offset(offset)
50
+ offset.current || :earliest_offset
51
+ end
52
+
49
53
  def fetch_messages
50
54
  @consumer.fetch.each do |message|
51
55
  Kafka.statsd.increment("messages.received")
@@ -0,0 +1,19 @@
1
+ module CC
2
+ module Kafka
3
+ module OffsetStorage
4
+ Memory = Struct.new(:topic, :partition, :current) do
5
+ def self.transaction
6
+ yield
7
+ end
8
+
9
+ def self.find_or_create!(attrs)
10
+ @offset ||= new(attrs[:topic], attrs[:partition], nil)
11
+ end
12
+
13
+ def set(attrs)
14
+ attrs.each { |k, v| self[k] = v }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module CC
2
+ module Kafka
3
+ module OffsetStorage
4
+ module Minidoc
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.include ::Minidoc::Indexes
8
+
9
+ base.attribute :topic, String
10
+ base.attribute :partition, Integer
11
+ base.attribute :current, Integer
12
+
13
+ base.ensure_index [:partition, :topic], unique: true
14
+ end
15
+
16
+ module ClassMethods
17
+ def find_or_create!(attributes)
18
+ find_one(attributes) || create!(attributes)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Kafka
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
data/lib/cc/kafka.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "logger"
2
2
  require "cc/kafka/consumer"
3
+ require "cc/kafka/offset_storage/memory"
4
+ require "cc/kafka/offset_storage/minidoc"
3
5
  require "cc/kafka/producer"
4
6
 
5
7
  module CC
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson
@@ -74,6 +74,8 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - lib/cc/kafka.rb
76
76
  - lib/cc/kafka/consumer.rb
77
+ - lib/cc/kafka/offset_storage/memory.rb
78
+ - lib/cc/kafka/offset_storage/minidoc.rb
77
79
  - lib/cc/kafka/producer.rb
78
80
  - lib/cc/kafka/producer/http.rb
79
81
  - lib/cc/kafka/producer/poseidon.rb