highwatermark 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d67e8b432cd252b44a7762911b7e843d7428ecd
4
+ data.tar.gz: c2e20e747e345dbaafc958ef2e99708bf79d1b73
5
+ SHA512:
6
+ metadata.gz: 57cece41916a74fe24581195220ed77a1ef86d15d41fa13609eb1afab3621a429dd92b6bf22ef97466965cec13483e0b4b236f21a56e87933815617313c9f5e8
7
+ data.tar.gz: a094b495a0b5f89f25b1a49ada162ef9ccddb4750f609c5a2dcfeb18c598aff1b76ea3a3bce169141d90f9605a2007e62f2840088c67f01cbcec0f149298a796
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in highwatermark.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ling Zhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Highwatermark
2
+
3
+ This gem is for storing your high watermark in state file or redis cache.
4
+
5
+ If not set up state file or redis, it will just use memory
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'highwatermark'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install highwatermark
22
+
23
+ ## Usage
24
+
25
+ In your ruby code:
26
+ ```ruby
27
+ # To initilize high watermark
28
+ require 'highwatermark'
29
+
30
+ path = "/path/to/state/file/or/redis/conf" # the file path for store state or the redis configure
31
+ state_type = "file" # state_type: could be <redis/file/memory>
32
+ tag = "your tag" # tag: is the tag that will be used in state file or redis
33
+
34
+ hwm = Highwatermark::HighWaterMark.new(path, state_type, tag)
35
+
36
+ # To store time in high watermark
37
+ time = "what your want to store in high watermark"
38
+ hwm.update_records(time)
39
+
40
+ # To get the high watermark
41
+ hwm.last_records()
42
+
43
+ ```
44
+
45
+ Example of redis.conf (if set state_type = 'redis'):
46
+
47
+ ```
48
+ # redis configure
49
+ host: 127.0.0.1
50
+ port: 6379
51
+
52
+ ```
53
+
54
+ ## Test
55
+
56
+ Install rake and minitest,then use rake run the test
57
+
58
+ ```
59
+ gem install minitest
60
+ gem install rake
61
+ rake test --trace
62
+
63
+ ```
64
+
65
+
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it ( https://github.com/[my-github-username]/highwatermark/fork )
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
10
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "highwatermark"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'highwatermark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "highwatermark"
8
+ spec.version = Highwatermark::VERSION
9
+ spec.authors = ["Ling Zhang"]
10
+ spec.email = ["zhangling.ice@gmail.com"]
11
+
12
+ # if spec.respond_to?(:metadata)
13
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ # end
15
+
16
+ spec.summary = %q{High Watermark store and update}
17
+ spec.description = %q{store High Watermark in state file and update it periodically}
18
+ spec.homepage = "https://github.com/lingzhang-lyon/highwatermark"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "redis"
29
+ spec.add_development_dependency "yaml"
30
+
31
+ end
@@ -0,0 +1,102 @@
1
+ require "highwatermark/version"
2
+
3
+ module Highwatermark
4
+ class HighWaterMark
5
+ def initialize(path,state_type,tag)
6
+ # path: is th file path for store state or the redis configure
7
+ # state_type: could be <redis/file/memory>
8
+ # tag: is the tag that will be used in state file or redis
9
+
10
+
11
+ require 'yaml'
12
+ require 'pp'
13
+ @path = path
14
+ @state_type = state_type
15
+ @tag = tag
16
+
17
+ @data = {}
18
+ if @state_type =='file'
19
+ if File.exists?(path)
20
+ @data = YAML.load_file(path)
21
+ if @data == false || @data == []
22
+ # this happens if an users created an empty file accidentally
23
+ @data = {}
24
+ elsif !@data.is_a?(Hash)
25
+ raise "state_file on #{@path.inspect} is invalid"
26
+ end
27
+ else
28
+ @data = {}
29
+ end
30
+ elsif @state_type =='memory'
31
+ @data = {}
32
+ elsif @state_type =='redis'
33
+ require 'redis'
34
+ $redis = if File.exists?(path)
35
+ redis_config = YAML.load_file(path)
36
+ # Connect to Redis using the redis_config host and port
37
+ if path
38
+ begin
39
+ pp "In redis #{path} Host #{redis_config['host']} port #{redis_config['port']}"
40
+ $redis = Redis.new(host: redis_config['host'], port: redis_config['port'])
41
+ rescue Exception => e
42
+ pp e.message
43
+ pp e.backtrace.inspect
44
+ end
45
+ end
46
+ else
47
+ Redis.new
48
+ end
49
+ @data = {}
50
+ end # end of checking @state_type
51
+ @data['last_records'] = {}
52
+ end # end of intitialize
53
+
54
+ def last_records()
55
+ if @state_type == 'file'
56
+ # return @data[@tag]
57
+ return @data['last_records'][@tag]
58
+ elsif @state_type =='memory'
59
+ return @data['last_records'][@tag]
60
+ elsif @state_type =='redis'
61
+ begin
62
+ alertStart=$redis.get(@tag)
63
+ return alertStart
64
+ rescue Exception => e
65
+ pp e.message
66
+ pp e.backtrace.inspect
67
+ end
68
+ end
69
+ end
70
+
71
+ def update_records(time)
72
+ if @state_type == 'file'
73
+ # @data[@tag] = time
74
+ @data['last_records'][@tag] = time
75
+ # $log.info @data
76
+ File.open(@path, 'w') {|f|
77
+ f.write YAML.dump(@data)
78
+ }
79
+ elsif @state_type =='memory'
80
+ @data['last_records'][@tag] = time
81
+
82
+ elsif @state_type =='redis'
83
+ begin
84
+ alertStart=$redis.set(@tag,time)
85
+ rescue Exception => e
86
+ pp e.message
87
+ pp e.backtrace.inspect
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end # end of class Highwatermark
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ end
@@ -0,0 +1,3 @@
1
+ module Highwatermark
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: highwatermark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ling Zhang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yaml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: store High Watermark in state file and update it periodically
70
+ email:
71
+ - zhangling.ice@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - highwatermark.gemspec
86
+ - lib/highwatermark.rb
87
+ - lib/highwatermark/version.rb
88
+ homepage: https://github.com/lingzhang-lyon/highwatermark
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: High Watermark store and update
112
+ test_files: []