highwatermark 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d67e8b432cd252b44a7762911b7e843d7428ecd
4
- data.tar.gz: c2e20e747e345dbaafc958ef2e99708bf79d1b73
3
+ metadata.gz: 6837c0694bb9f29f4708ae5998a8368dbec1e6cb
4
+ data.tar.gz: ead1e5d238bc2d39297b132c1d1518d457d424a4
5
5
  SHA512:
6
- metadata.gz: 57cece41916a74fe24581195220ed77a1ef86d15d41fa13609eb1afab3621a429dd92b6bf22ef97466965cec13483e0b4b236f21a56e87933815617313c9f5e8
7
- data.tar.gz: a094b495a0b5f89f25b1a49ada162ef9ccddb4750f609c5a2dcfeb18c598aff1b76ea3a3bce169141d90f9605a2007e62f2840088c67f01cbcec0f149298a796
6
+ metadata.gz: 842a1d1b2247328656a0bbcc55c3de0f3a1ae83abe3ba54ee677dfeefd04dd851ad261a886189f316c54b896aa91820feafcc3ad4d62c80ecf7ede7dcbcbb802
7
+ data.tar.gz: d8eecbc421d6067f634ec8eea7fc9c4fab74a62c977945218667042d795cf6605a390e38a8f46e3b52e5b92e87b3a080b1063d1b1f12700abde2f83e52afaabd
data/README.md CHANGED
@@ -31,14 +31,14 @@ path = "/path/to/state/file/or/redis/conf" # the file path for store state or
31
31
  state_type = "file" # state_type: could be <redis/file/memory>
32
32
  tag = "your tag" # tag: is the tag that will be used in state file or redis
33
33
 
34
- hwm = Highwatermark::HighWaterMark.new(path, state_type, tag)
34
+ hwm = Highwatermark::HighWaterMark.new(path, state_type)
35
35
 
36
36
  # To store time in high watermark
37
37
  time = "what your want to store in high watermark"
38
- hwm.update_records(time)
38
+ hwm.update_records(time, tag)
39
39
 
40
40
  # To get the high watermark
41
- hwm.last_records()
41
+ hwm.last_records(tag)
42
42
 
43
43
  ```
44
44
 
@@ -49,7 +49,17 @@ Example of redis.conf (if set state_type = 'redis'):
49
49
  host: 127.0.0.1
50
50
  port: 6379
51
51
 
52
- ```
52
+ ```
53
+
54
+ Output in the state file:
55
+
56
+ ```
57
+ ---
58
+ last_records:
59
+ your tag: 1429572200
60
+
61
+ ```
62
+
53
63
 
54
64
  ## Test
55
65
 
@@ -1,3 +1,3 @@
1
1
  module Highwatermark
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/highwatermark.rb CHANGED
@@ -2,7 +2,8 @@ require "highwatermark/version"
2
2
 
3
3
  module Highwatermark
4
4
  class HighWaterMark
5
- def initialize(path,state_type,tag)
5
+ # def initialize(path,state_type,tag)
6
+ def initialize(path,state_type)
6
7
  # path: is th file path for store state or the redis configure
7
8
  # state_type: could be <redis/file/memory>
8
9
  # tag: is the tag that will be used in state file or redis
@@ -12,12 +13,13 @@ module Highwatermark
12
13
  require 'pp'
13
14
  @path = path
14
15
  @state_type = state_type
15
- @tag = tag
16
+ # @tag = tag
16
17
 
17
18
  @data = {}
18
19
  if @state_type =='file'
19
20
  if File.exists?(path)
20
21
  @data = YAML.load_file(path)
22
+ pp @data
21
23
  if @data == false || @data == []
22
24
  # this happens if an users created an empty file accidentally
23
25
  @data = {}
@@ -48,18 +50,24 @@ module Highwatermark
48
50
  end
49
51
  @data = {}
50
52
  end # end of checking @state_type
51
- @data['last_records'] = {}
53
+
54
+ if @data['last_records']==nil
55
+ @data['last_records'] = {}
56
+ end
57
+
52
58
  end # end of intitialize
53
59
 
54
- def last_records()
60
+ def last_records(tag)
55
61
  if @state_type == 'file'
56
62
  # return @data[@tag]
57
- return @data['last_records'][@tag]
63
+ # pp @data['last_records'][tag]
64
+ return @data['last_records'][tag]
65
+
58
66
  elsif @state_type =='memory'
59
- return @data['last_records'][@tag]
67
+ return @data['last_records'][tag]
60
68
  elsif @state_type =='redis'
61
69
  begin
62
- alertStart=$redis.get(@tag)
70
+ alertStart=$redis.get(tag)
63
71
  return alertStart
64
72
  rescue Exception => e
65
73
  pp e.message
@@ -68,20 +76,20 @@ module Highwatermark
68
76
  end
69
77
  end
70
78
 
71
- def update_records(time)
79
+ def update_records(time, tag)
72
80
  if @state_type == 'file'
73
81
  # @data[@tag] = time
74
- @data['last_records'][@tag] = time
82
+ @data['last_records'][tag] = time
75
83
  # $log.info @data
76
84
  File.open(@path, 'w') {|f|
77
85
  f.write YAML.dump(@data)
78
86
  }
79
87
  elsif @state_type =='memory'
80
- @data['last_records'][@tag] = time
88
+ @data['last_records'][tag] = time
81
89
 
82
90
  elsif @state_type =='redis'
83
91
  begin
84
- alertStart=$redis.set(@tag,time)
92
+ alertStart=$redis.set(tag,time)
85
93
  rescue Exception => e
86
94
  pp e.message
87
95
  pp e.backtrace.inspect
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highwatermark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ling Zhang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler