activerecord-overflow_signalizer 0.1.1 → 1.0.0
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 +4 -4
- data/.travis.yml +5 -0
- data/Appraisals +5 -1
- data/README.md +14 -12
- data/lib/activerecord/overflow_signalizer.rb +15 -4
- data/lib/activerecord/overflow_signalizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c78090d0511bef9b0dde4bd9806e69d46de9dfd7
|
4
|
+
data.tar.gz: 80ff96314dcf36dda7275149eff74840ef4653ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afb0998fb161bd0f060bd8cc92f8d3e82b9cb73997169b97fe7f4129b15628c8e877af8ffc1dc80c0e51095913dcea52b691e4eb52513bf123eb935e510b17d
|
7
|
+
data.tar.gz: e7ed9f015e87d1d0e678bd9d5f070de49d4a8dfd34bee422f8ff0cfb880c5e4a61750132652b8467119910c3b4044a1534637989d76ce6230e403367adf263ff
|
data/.travis.yml
CHANGED
@@ -4,6 +4,11 @@ gemfile:
|
|
4
4
|
- gemfiles/ar32.gemfile
|
5
5
|
- gemfiles/ar42.gemfile
|
6
6
|
- gemfiles/ar50.gemfile
|
7
|
+
- gemfiles/ar51.gemfile
|
7
8
|
rvm:
|
8
9
|
- 2.3.1
|
10
|
+
addons:
|
11
|
+
postgresql: '9.4'
|
12
|
+
before_script:
|
13
|
+
- psql -U postgres -c 'CREATE DATABASE overflow_analyzer_test'
|
9
14
|
before_install: gem install bundler -v 1.14.4
|
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# ActiveRecord::OverflowSignalizer
|
2
|
+
[](https://travis-ci.org/funbox/activerecord-overflow_signalizer)
|
2
3
|
|
3
|
-
One day primary key field will overflow, but if you use this gem, you will know about it before it
|
4
|
+
One day primary key field will overflow, but if you use this gem, you will know about it before it happens.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -20,17 +21,18 @@ Or install it yourself as:
|
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
23
|
-
Just
|
24
|
+
Just place it somewhere in your app:
|
24
25
|
```ruby
|
25
|
-
ActiveRecord::OverflowSignalizer.new.analyse
|
26
|
+
ActiveRecord::OverflowSignalizer.new.analyse
|
26
27
|
```
|
27
28
|
|
28
|
-
By default it
|
29
|
+
By default it checks all models in your application and logs if some primary key will overflow soon or overflowed.
|
30
|
+
Also you can use unsafe method `#analyse!`, so it will raise error.
|
29
31
|
|
30
|
-
You can
|
31
|
-
or just run it when app
|
32
|
+
You can place it in some job and perform it by [clockwork](https://github.com/adamwiggins/clockwork)
|
33
|
+
or just run it when app starts in a separate thread.
|
32
34
|
|
33
|
-
Also you can pass some parameters
|
35
|
+
Also you can pass some parameters to the initializer:
|
34
36
|
|
35
37
|
+ Specify logger
|
36
38
|
```ruby
|
@@ -42,15 +44,15 @@ By default ActiveRecord::Base.logger
|
|
42
44
|
```ruby
|
43
45
|
ActiveRecord::OverflowSignalizer.new(models: [ModelName])
|
44
46
|
```
|
45
|
-
By default it
|
47
|
+
By default it retrieves all descendants of ActiveRecord::Base
|
46
48
|
|
47
|
-
+ Specify count of days. Gem
|
49
|
+
+ Specify count of days. Gem starts to notify you if some primary key will overflow over the next number of days.
|
48
50
|
```ruby
|
49
51
|
ActiveRecord::OverflowSignalizer.new(days_count: 360)
|
50
52
|
```
|
51
53
|
60 days by default
|
52
54
|
|
53
|
-
+ You can use own signalizer for sending
|
55
|
+
+ You can use your own signalizer for notification sending to e-mail, slack, hipchat, etc.
|
54
56
|
```ruby
|
55
57
|
class MyAwesomeSignalizer
|
56
58
|
def initialize(some_params)
|
@@ -64,11 +66,11 @@ end
|
|
64
66
|
|
65
67
|
ActiveRecord::OverflowSignalizer.new(signalizer: MyAwesomeSignalizer.new(some_params))
|
66
68
|
```
|
67
|
-
By default it
|
69
|
+
By default it uses only logging
|
68
70
|
|
69
71
|
## Development
|
70
72
|
|
71
|
-
For tests you need postgresql connection specified in `spec/database.yml`.
|
73
|
+
For tests you need a postgresql connection specified in `spec/database.yml`.
|
72
74
|
|
73
75
|
## Contributing
|
74
76
|
|
@@ -3,6 +3,8 @@ require 'active_record'
|
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
5
|
class OverflowSignalizer
|
6
|
+
class Overflow < StandardError; end
|
7
|
+
|
6
8
|
class UnsupportedType < StandardError
|
7
9
|
attr_reader :type
|
8
10
|
|
@@ -33,11 +35,17 @@ module ActiveRecord
|
|
33
35
|
pk = model.columns.select { |c| c.name == model.primary_key }.first
|
34
36
|
max = MAX_VALUE.fetch(pk.sql_type) { |type| raise UnsupportedType, type }
|
35
37
|
if overflow_soon?(max, model)
|
36
|
-
|
38
|
+
raise Overflow, overflow_message(table, model.last.public_send(pk.name), max)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
def analyse
|
44
|
+
analyse!
|
45
|
+
rescue Overflow => e
|
46
|
+
signalize(e.message)
|
47
|
+
end
|
48
|
+
|
41
49
|
private
|
42
50
|
|
43
51
|
def overflow_soon?(max, model)
|
@@ -58,12 +66,15 @@ module ActiveRecord
|
|
58
66
|
week_records.reduce(:+) / week_records.keep_if { |v| v > 0 }.size
|
59
67
|
end
|
60
68
|
|
61
|
-
def
|
69
|
+
def overflow_message(table, current_value, max_value)
|
62
70
|
if current_value == max_value
|
63
|
-
|
71
|
+
"Primary key in table #{table} overflowed! #{current_value} from #{max_value}"
|
64
72
|
else
|
65
|
-
|
73
|
+
"Primary key in table #{table} will overflow soon! #{current_value} from #{max_value}"
|
66
74
|
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def signalize(msg)
|
67
78
|
if @logger && @logger.respond_to?(:warn)
|
68
79
|
@logger.warn(msg)
|
69
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-overflow_signalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- v.promzelev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|