cleansweep 1.0.4 → 1.0.5
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/CHANGES.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -4
- data/lib/clean_sweep/purge_runner.rb +3 -4
- data/lib/clean_sweep/purge_runner/logging.rb +2 -2
- data/lib/clean_sweep/version.rb +1 -1
- data/spec/purge_runner_spec.rb +41 -4
- data/spec/spec_helper.rb +4 -0
- 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: 5af728c3efc79bc3cec89d0ee6d3d109b5ba4481
|
4
|
+
data.tar.gz: 53d6d9bcdc7c4d9532931bd144274624e824df22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 370455a298b5a0a5fada8b5521e7ccb8fcdc12aada97761a65ffd8f54a33538c7bbaaf9356a644f6b5c95f610b55c6bbfb0a7a16a728604c23289ff46ce840f9
|
7
|
+
data.tar.gz: ac7b4a332aa6c8aa375ab759ebe51cd28c907cd8b41a6b17f777cd228c9830883e61039685ac59ee5bf716b5f98221d29d3812804413b293acc2575dab06ed65
|
data/CHANGES.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,10 @@ Cleansweep is a utility for scripting purges using ruby in an
|
|
2
2
|
efficient, low-impact manner on mysql innodb tables. Based on the
|
3
3
|
Percona `pt-archive` utility.
|
4
4
|
|
5
|
-
[](https://travis-ci.org/bkayser/cleansweep)
|
6
|
+
[](https://codeclimate.com/github/bkayser/cleansweep)
|
7
|
+
[](https://codeclimate.com/github/bkayser/cleansweep)
|
8
|
+
[](http://badge.fury.io/rb/cleansweep)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -139,7 +140,7 @@ week are copied.
|
|
139
140
|
index: 'comments_on_account_timestamp',
|
140
141
|
dest_model: ExpiredComment,
|
141
142
|
copy_only: true,
|
142
|
-
copy_columns: %w[liked] do
|
143
|
+
copy_columns: %w[liked] do | model |
|
143
144
|
model.where('last_used_at < ?', 1.week.ago)
|
144
145
|
end
|
145
146
|
```
|
@@ -123,8 +123,9 @@ class CleanSweep::PurgeRunner
|
|
123
123
|
raise "An index is required in copy mode" if copy_mode? && @table_schema.traversing_key.nil?
|
124
124
|
raise "first_only option not allowed in copy mode" if copy_mode? && @table_schema.first_only?
|
125
125
|
|
126
|
-
@
|
127
|
-
|
126
|
+
@start = Time.now
|
127
|
+
@report_interval_start = @start
|
128
|
+
@total_deleted = 0
|
128
129
|
@query = @table_schema.initial_scope.limit(@limit)
|
129
130
|
|
130
131
|
@query = yield(@query) if block_given?
|
@@ -148,7 +149,6 @@ class CleanSweep::PurgeRunner
|
|
148
149
|
return 0
|
149
150
|
end
|
150
151
|
|
151
|
-
@start = Time.now
|
152
152
|
verb = copy_mode? ? "copying" : "purging"
|
153
153
|
|
154
154
|
msg = "starting: #{verb} #{@table_schema.name} records in batches of #@limit"
|
@@ -156,7 +156,6 @@ class CleanSweep::PurgeRunner
|
|
156
156
|
|
157
157
|
|
158
158
|
log :info, "sleeping #{@sleep} seconds between purging" if @sleep && !copy_mode?
|
159
|
-
@total_deleted = 0
|
160
159
|
|
161
160
|
# Iterate through the rows in limit chunks
|
162
161
|
log :debug, "find rows: #{@query.to_sql}" if @logger.level == Logger::DEBUG
|
@@ -3,7 +3,7 @@ module CleanSweep::PurgeRunner::Logging
|
|
3
3
|
def report(force=false)
|
4
4
|
report_duration = Time.now - @report_interval_start
|
5
5
|
if (force || report_duration >= @report_interval)
|
6
|
-
while (@report_interval_start < Time.now - @report_interval) do
|
6
|
+
while (@report_interval > 0 && @report_interval_start < Time.now - @report_interval) do
|
7
7
|
@report_interval_start += @report_interval
|
8
8
|
end
|
9
9
|
print_report
|
@@ -49,7 +49,7 @@ module CleanSweep::PurgeRunner::Logging
|
|
49
49
|
if (time.to_i > (24 * 60 * 60))
|
50
50
|
format_string = "%d days, %H:%M"
|
51
51
|
end
|
52
|
-
Time.at(time).strftime(format_string)
|
52
|
+
Time.at(time).utc.strftime(format_string)
|
53
53
|
end
|
54
54
|
|
55
55
|
def print_report
|
data/lib/clean_sweep/version.rb
CHANGED
data/spec/purge_runner_spec.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
|
-
# Time mocking features are available in Rails 4 but not Rails 3 and the Timecop
|
4
|
-
# gem works with both.
|
5
|
-
require 'timecop'
|
2
|
+
require 'logger'
|
6
3
|
|
7
4
|
describe CleanSweep::PurgeRunner do
|
8
5
|
|
@@ -165,6 +162,40 @@ EOF
|
|
165
162
|
expect(Book.count).to be 0
|
166
163
|
end
|
167
164
|
|
165
|
+
context "logging" do
|
166
|
+
before do
|
167
|
+
@buffer = StringIO.new
|
168
|
+
logger = Logger.new(@buffer)
|
169
|
+
logger.formatter = SimpleFormatter.new
|
170
|
+
@purger = CleanSweep::PurgeRunner.new model: Book,
|
171
|
+
chunk_size: 4,
|
172
|
+
logger: logger,
|
173
|
+
report: 5.minutes
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should log correct timestamps' do
|
178
|
+
Timecop.freeze 90.seconds.from_now
|
179
|
+
@purger.report(true)
|
180
|
+
expect(@buffer.string).to eq <<EOF
|
181
|
+
** report:
|
182
|
+
** deleted: 0 books records
|
183
|
+
** elapsed: 00:01:30
|
184
|
+
** rate: < 1 records/second
|
185
|
+
EOF
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should log at correct intervals' do
|
189
|
+
Timecop.freeze 4.minutes.from_now
|
190
|
+
@purger.report
|
191
|
+
expect(@buffer.string).to eq ""
|
192
|
+
|
193
|
+
Timecop.freeze 6.minutes.from_now
|
194
|
+
@purger.report
|
195
|
+
expect(@buffer.string).to_not be_empty
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
168
199
|
it 'copies books' do
|
169
200
|
BookTemp.create_table
|
170
201
|
purger = CleanSweep::PurgeRunner.new model: Book,
|
@@ -225,6 +256,12 @@ describe CleanSweep::PurgeRunner::MysqlStatus do
|
|
225
256
|
end
|
226
257
|
end
|
227
258
|
|
259
|
+
class SimpleFormatter < ::Logger::Formatter
|
260
|
+
def call(severity, timestamp, progname, msg)
|
261
|
+
"#{msg}\n"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
228
265
|
end
|
229
266
|
|
230
267
|
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,11 @@ require 'factory_girl'
|
|
7
7
|
require 'fileutils'
|
8
8
|
require 'active_record'
|
9
9
|
require 'mysql2'
|
10
|
+
|
11
|
+
# Time mocking features are available in Rails 4 but not Rails 3 and the Timecop
|
12
|
+
# gem works with both.
|
10
13
|
require 'timecop'
|
14
|
+
|
11
15
|
RSpec.configure do |config|
|
12
16
|
config.include FactoryGirl::Syntax::Methods
|
13
17
|
config.formatter = :progress
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cleansweep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Kayser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|