cleansweep 1.0.4 → 1.0.5

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: f772f74727a7d58fdebda097fb0b70572cb92c34
4
- data.tar.gz: a82986ae0e26308e4842193441e427e998c4f5a0
3
+ metadata.gz: 5af728c3efc79bc3cec89d0ee6d3d109b5ba4481
4
+ data.tar.gz: 53d6d9bcdc7c4d9532931bd144274624e824df22
5
5
  SHA512:
6
- metadata.gz: 183922164f35fbd986ca9617fa1c73fc4133db90fc15a59552f48def16a8d39d8a8164bbef8d61ee334f6a8dffbfc74a34f5fbb182d446d7485372b6add8667a
7
- data.tar.gz: 77e4f14d2e44e7400d4bb14a09719fea8a13aac2660fab0712355b053d8117e848f7dd967878b01ec5c87c6181eca821056f4e388b00c93cd4b005432d1c0ebc
6
+ metadata.gz: 370455a298b5a0a5fada8b5521e7ccb8fcdc12aada97761a65ffd8f54a33538c7bbaaf9356a644f6b5c95f610b55c6bbfb0a7a16a728604c23289ff46ce840f9
7
+ data.tar.gz: ac7b4a332aa6c8aa375ab759ebe51cd28c907cd8b41a6b17f777cd228c9830883e61039685ac59ee5bf716b5f98221d29d3812804413b293acc2575dab06ed65
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  See the [documentation](http://bkayser.github.io/cleansweep) for details
2
2
 
3
+ ### Version 1.0.5
4
+
5
+ * Fix timestamp in interval reports which was off by timezone offset in hours.
6
+
3
7
  ### Version 1.0.4
4
8
 
5
9
  * Print dry run output using the logger
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cleansweep (1.0.4)
4
+ cleansweep (1.0.5)
5
5
  activerecord (>= 3.0)
6
6
  mysql2 (~> 0.3)
7
7
  newrelic_rpm
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
- [![Build Status](https://img.shields.io/travis/bkayser/cleansweep/master.svg?x=3)](https://travis-ci.org/bkayser/cleansweep)
6
- [![Code Climate](https://codeclimate.com/github/bkayser/cleansweep/badges/gpa.svg?x=3)](https://codeclimate.com/github/bkayser/cleansweep)
7
- [![Test Coverage](https://codeclimate.com/github/bkayser/cleansweep/badges/coverage.svg?x=3)](https://codeclimate.com/github/bkayser/cleansweep)
5
+ [![Build Status](https://img.shields.io/travis/bkayser/cleansweep/master.svg?x=4)](https://travis-ci.org/bkayser/cleansweep)
6
+ [![Code Climate](https://codeclimate.com/github/bkayser/cleansweep/badges/gpa.svg?x=4)](https://codeclimate.com/github/bkayser/cleansweep)
7
+ [![Test Coverage](https://codeclimate.com/github/bkayser/cleansweep/badges/coverage.svg?x=4)](https://codeclimate.com/github/bkayser/cleansweep)
8
+ [![Gem Version](https://badge.fury.io/rb/cleansweep.svg)](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 do | model |
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
- @report_interval_start = Time.now
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
@@ -1,3 +1,3 @@
1
1
  module CleanSweep
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -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
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-01-07 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord