bucket_cake 2.0.1 → 3.0.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: 971c717cd37127c460012f0458ec88770e7bb582
4
- data.tar.gz: 9667d6d81df2479dbcfd9636f75f0c78f93cc183
3
+ metadata.gz: 87c40cb79610b73decea42bbe95851d52ac91b42
4
+ data.tar.gz: 9cc67aee2afdb05469072c802e7b1ad5acd7e167
5
5
  SHA512:
6
- metadata.gz: cbeec6767901aafbe9dfd6b51f5a8d000b029ebbcf130766822917502928e50643f3d7280157490564e79081289e5029e4429d32caae36eb013af498d5feaf89
7
- data.tar.gz: d639a0956dbd956221c6821b5254483ab494622955e65e345c49296d010aeb8ad6cfd70bfc8e136519ac6a91d0ed75da2b3f8bd4c76194fa4917338452d5367c
6
+ metadata.gz: f2355e18dccb3ddce2f141ae7a0740a5721f12df438dbadcfc7911e1d19ea72e9432985ebc188968a2010ce3f594c5cdb021de933c25e794135fe2bef7287732
7
+ data.tar.gz: e8fd595e130a1e8d4284b240000941335eb7b65871ee621d5864a19bce5623c014ffe80b154db2aa2f1c4a506f68dbea02cbacc3e9fed63af0b6d23edfe4134f
data/lib/bucket_cake.rb CHANGED
@@ -29,5 +29,5 @@ require 'bucket_cake/facts'
29
29
  Protobuf.ignore_unknown_fields = false
30
30
 
31
31
  module BucketCake
32
- CACHE_PREFIX = 'bucket-cake-latest'
32
+ CURSOR_REGEXP = %r{\A\d{4}/\d{2}/\d{2}/\d{6}\z}
33
33
  end
@@ -1,39 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
3
  class Base
4
- def initialize(cache)
5
- @cache = cache
6
- check_cache!
4
+ class Range < self
5
+ def initialize(cursor)
6
+ raise 'BucketCake: cursor has invalid format!' unless cursor.nil? || cursor =~ CURSOR_REGEXP
7
+ @cursor = cursor
8
+ end
9
+
10
+ def items
11
+ get Source::Range.new(self.class::FOLDER, cursor), self.class::PROTOCLASS
12
+ end
7
13
  end
8
14
 
9
- private
10
-
11
- attr_reader :cache
12
-
13
- def check_cache!
14
- return if cache && cache.respond_to?(:read) && cache.respond_to?(:write)
15
-
16
- raise 'BucketCake: cache parameter must respond to #read and #write. ' \
17
- 'Use Rails.cache if you are not sure.'
15
+ class Latest < self
16
+ def items
17
+ get Source::Latest.new(self.class::FOLDER, nil), self.class::PROTOCLASS
18
+ end
18
19
  end
19
20
 
20
- def latest(type, klass)
21
- get Source::Latest.new(type, cache), klass
22
- end
21
+ attr_reader :cursor
23
22
 
24
- def range(type, klass)
25
- get Source::Range.new(type, cache), klass
26
- end
23
+ private
27
24
 
28
25
  def get(source, klass)
29
- return unless source.new_data?
30
-
31
- Enumerator.new do |y|
32
- Decoder.new(source.zip_files, klass).items.each do |item|
33
- y << item
34
- end
35
- source.confirm!
36
- end.lazy
26
+ @cursor = source.latest_cursor
27
+ Decoder.new(source.zip_files, klass).items.lazy
37
28
  end
38
29
  end
39
30
  end
@@ -1,24 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
- class Entities < Base
4
- def advertisers
5
- latest 'advertisers', Cakeproto::Advertiser
3
+ module Entities
4
+ class Advertisers < Base::Latest
5
+ FOLDER = 'advertisers'
6
+ PROTOCLASS = Cakeproto::Advertiser
6
7
  end
7
8
 
8
- def affiliates
9
- latest 'affiliates', Cakeproto::Affiliate
9
+ class Affiliates < Base::Latest
10
+ FOLDER = 'affiliates'
11
+ PROTOCLASS = Cakeproto::Affiliate
10
12
  end
11
13
 
12
- def campaigns
13
- latest 'campaigns', Cakeproto::Campaign
14
+ class Campaigns < Base::Latest
15
+ FOLDER = 'campaigns'
16
+ PROTOCLASS = Cakeproto::Campaign
14
17
  end
15
18
 
16
- def creatives
17
- latest 'creatives', Cakeproto::Creative
19
+ class Creatives < Base::Latest
20
+ FOLDER = 'creatives'
21
+ PROTOCLASS = Cakeproto::Creative
18
22
  end
19
23
 
20
- def offers
21
- latest 'offers', Cakeproto::Offer
24
+ class Offers < Base::Latest
25
+ FOLDER = 'offers'
26
+ PROTOCLASS = Cakeproto::Offer
22
27
  end
23
28
  end
24
29
  end
@@ -1,24 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
- class Facts < Base
4
- def clicks
5
- range 'clicks', Cakeproto::Click
3
+ module Facts
4
+ class Clicks < Base::Range
5
+ FOLDER = 'clicks'
6
+ PROTOCLASS = Cakeproto::Click
6
7
  end
7
8
 
8
- def conversions
9
- range 'conversions', Cakeproto::Conversion
9
+ class Conversions < Base::Range
10
+ FOLDER = 'conversions'
11
+ PROTOCLASS = Cakeproto::Conversion
10
12
  end
11
13
 
12
- def conversion_changes
13
- range 'conversion_changes', Cakeproto::ConversionChange
14
+ class ConversionChanges < Base::Range
15
+ FOLDER = 'conversion_changes'
16
+ PROTOCLASS = Cakeproto::ConversionChange
14
17
  end
15
18
 
16
- def cap_states
17
- range 'cap_states', Cakeproto::CapState
18
- end
19
+ class CapStates < Base::Range
20
+ FOLDER = 'cap_states'
21
+ PROTOCLASS = Cakeproto::CapState
19
22
 
20
- def latest_cap_states
21
- latest 'cap_states', Cakeproto::CapState
23
+ class Latest < Base::Latest
24
+ FOLDER = 'cap_states'
25
+ PROTOCLASS = Cakeproto::CapState
26
+ end
22
27
  end
23
28
  end
24
29
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
3
  class Source
4
- def initialize(type, cache)
5
- @type = type
6
- @cache = cache
4
+ def initialize(folder, cursor)
5
+ @folder = folder
6
+ @cursor = cursor
7
7
  end
8
8
 
9
9
  def zip_files
@@ -22,6 +22,14 @@ module BucketCake
22
22
  end
23
23
  end
24
24
 
25
+ def latest_cursor
26
+ @latest_cursor ||= bucket.object("#{folder}/latest").get.body.read
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :folder, :cursor
32
+
25
33
  def check_success(key)
26
34
  @success_files ||= Set.new
27
35
  @success_files << key if key.end_with?('/SUCCESS')
@@ -31,30 +39,6 @@ module BucketCake
31
39
  @success_files.include?(File.dirname(key) + '/SUCCESS')
32
40
  end
33
41
 
34
- def new_data?
35
- current_latest_path != cache_latest_path
36
- end
37
-
38
- def confirm!
39
- cache.write(cache_key, current_latest_path)
40
- end
41
-
42
- private
43
-
44
- attr_reader :type, :cache
45
-
46
- def cache_key
47
- "#{CACHE_PREFIX}-#{type}"
48
- end
49
-
50
- def current_latest_path
51
- @current_latest_path ||= bucket.object("#{type}/latest").get.body.read
52
- end
53
-
54
- def cache_latest_path
55
- @cache_latest_path ||= cache.read(cache_key)
56
- end
57
-
58
42
  def bucket
59
43
  @bucket ||= Aws::S3::Bucket.new(ENV.fetch('CAKE_DATA_BUCKET'))
60
44
  end
@@ -64,7 +48,7 @@ module BucketCake
64
48
  private
65
49
 
66
50
  def objects
67
- bucket.objects(prefix: "#{type}/#{current_latest_path}/")
51
+ bucket.objects(prefix: "#{folder}/#{latest_cursor}/")
68
52
  end
69
53
  end
70
54
 
@@ -72,13 +56,13 @@ module BucketCake
72
56
  private
73
57
 
74
58
  def objects
75
- # If we don't have a timestamp in cache, return everything
76
- return bucket.objects(prefix: "#{type}/") if cache_latest_path.nil?
59
+ # If we don't have a timestamp in cursor, return everything
60
+ return bucket.objects(prefix: "#{folder}/") if cursor.nil?
77
61
 
78
62
  # This returns all objects after the current timestamp.
79
63
  # By using the 'xxx' suffix, none of the objects of the given timestamp are returned.
80
64
  # S3 ensures alphabetical order of the results, so this works fine for date ranges.
81
- bucket.objects(marker: "#{type}/#{cache_latest_path}/xxx", prefix: "#{type}/")
65
+ bucket.objects(marker: "#{folder}/#{cursor}/xxx", prefix: "#{folder}/")
82
66
  end
83
67
  end
84
68
  end
@@ -1,36 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
- class Values < Base
4
- def affiliate_tiers
5
- latest 'affiliate_tiers', Cakeproto::IdName
3
+ module Values
4
+ class AffiliateTiers < Base::Latest
5
+ FOLDER = 'affiliate_tiers'
6
+ PROTOCLASS = Cakeproto::IdName
6
7
  end
7
8
 
8
- def blacklist_reasons
9
- latest 'blacklist_reasons', Cakeproto::IdName
9
+ class BlacklistReasons < Base::Latest
10
+ FOLDER = 'blacklist_reasons'
11
+ PROTOCLASS = Cakeproto::IdName
10
12
  end
11
13
 
12
- def countries
13
- latest 'countries', Cakeproto::Country
14
+ class Countries < Base::Latest
15
+ FOLDER = 'countries'
16
+ PROTOCLASS = Cakeproto::Country
14
17
  end
15
18
 
16
- def currencies
17
- latest 'currencies', Cakeproto::Currency
19
+ class Currencies < Base::Latest
20
+ FOLDER = 'currencies'
21
+ PROTOCLASS = Cakeproto::Currency
18
22
  end
19
23
 
20
- def exchange_rates
21
- latest 'exchange_rates', Cakeproto::ExchangeRate
24
+ class ExchangeRates < Base::Latest
25
+ FOLDER = 'exchange_rates'
26
+ PROTOCLASS = Cakeproto::ExchangeRate
22
27
  end
23
28
 
24
- def media_types
25
- latest 'media_types', Cakeproto::IdName
29
+ class MediaTypes < Base::Latest
30
+ FOLDER = 'media_types'
31
+ PROTOCLASS = Cakeproto::IdName
26
32
  end
27
33
 
28
- def payment_types
29
- latest 'payment_types', Cakeproto::IdName
34
+ class PaymentTypes < Base::Latest
35
+ FOLDER = 'payment_types'
36
+ PROTOCLASS = Cakeproto::IdName
30
37
  end
31
38
 
32
- def verticals
33
- latest 'verticals', Cakeproto::IdName
39
+ class Verticals < Base::Latest
40
+ FOLDER = 'verticals'
41
+ PROTOCLASS = Cakeproto::IdName
34
42
  end
35
43
  end
36
44
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module BucketCake
3
- VERSION = '2.0.1'
3
+ VERSION = '3.0.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bucket_cake
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: activesupport
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: bundler
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
196
  version: '0'
211
197
  requirements: []
212
198
  rubyforge_project:
213
- rubygems_version: 2.5.1
199
+ rubygems_version: 2.6.4
214
200
  signing_key:
215
201
  specification_version: 4
216
202
  summary: Get cakeproto objects from S3.