resque-reports 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGI4MGEyNzY1NmNlOTM5YmY4YzY2MGNhMzQ1NDExZWYwMDE5MTRmYw==
4
+ YTg1YTcwMDRhNWJhYTViN2I1NjVmYzMxODQwNjBjNmZlZGEyNDg2Nw==
5
5
  data.tar.gz: !binary |-
6
- ZTQyNzM2NmZiODU0NzkyYzE0MmUxNDkzYWUzYjVlMzQwOGFiYzI2Nw==
6
+ MWY4NWZhNzZlN2MyNmYzMjVlMWU0ODA0M2Q2M2E4Mjg5ZmJjZjE4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzNkOTVlZDgzZjE1MTE3NjFkMTU1MjAwMDVmNDQyYTVkZjk5YmVjZjU1MmVm
10
- MzBlNWNjZmRmYzBkMTg0MWRjMjk5OTQzNjU4NmVmZjRkZjdhNzY1YTc5YTg2
11
- ODI5MDIyNDI2YTI3ZDJkMzE2ZWE1ODdkMDgzMjBmYzQ4ZGVmZTU=
9
+ OTYyN2UxMzVlMDJlYWYyZjU0Yzc4ODE0NWQ3YzY1ZDQwZDdiZDY0MGMzYWJh
10
+ YzYyMmRiZjQ3N2U1ZjIzMjAzMDU2ZDQ3ZDFkY2RlNmVhMzAwZmRlZTkxNzEw
11
+ MDMxYWU1YmJjMmRiYzZkN2VmODVjZmIxMGJiYTg0YmQ0YTAzYjc=
12
12
  data.tar.gz: !binary |-
13
- NThmYmQzYTM4YWFmYmUzNmIyMDg5MGMwYzcxYmFhYTIzOWY2OGZlZTYxZTEw
14
- MmRkMjFhZTExMzIyMzJhMzkwMzMxMWQ2NzMwODk4YTU3YzFjZDFlYTI2YTdi
15
- OGM0ZmE0ZjdhNjg5MTFiN2ExZmI0OGE3MTg3NDA3N2M5NWM0YmE=
13
+ MGYwN2RhZGFiZWMxYzQyMTAyMzY5YWJmNGMwY2NjZjA2NzIyYTA4NGY2YzA3
14
+ NjliYmU2ZmEzOTU4MzViODNiNjhlMDJiZTNiNWEwNTQxZWNjMDc2MTM3ZjVi
15
+ Zjk2ZWU2YWI0ZWU2MzAyZGVjNGQ0MGUxNTA0NTYyMjMyYzlhZDQ=
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
+ source 'https://gems.railsc.ru'
1
2
  source 'https://rubygems.org'
2
- source 'http://apress:montalcino@gems.dev.apress.ru'
3
3
 
4
4
  # Specify your gem's dependencies in resque-reports.gemspec
5
5
  gemspec
@@ -28,6 +28,7 @@ module Resque
28
28
  # queue :custom_reports # Resque queue name
29
29
  # source :select_data # method called to retrieve report data
30
30
  # encoding UTF8 # file encoding
31
+ # expire_in 86_400 # cache time of the file, default: 86_400
31
32
  #
32
33
  # # Specify in which directory to keep this type files
33
34
  # directory File.join(Dir.tmpdir, 'resque-reports')
@@ -80,7 +81,8 @@ module Resque
80
81
  :_encoding,
81
82
  :_directory,
82
83
  :_queue,
83
- :_output_filename
84
+ :_output_filename,
85
+ :_expire_in
84
86
 
85
87
  alias_method :super_extension, :_extension
86
88
  alias_method :extension, :_extension=
@@ -88,6 +90,7 @@ module Resque
88
90
  alias_method :directory, :_directory=
89
91
  alias_method :queue, :_queue=
90
92
  alias_method :output_filename, :_output_filename=
93
+ alias_method :expire_in, :_expire_in=
91
94
 
92
95
  def set_instance(obj)
93
96
  @instance = obj
@@ -138,7 +141,8 @@ module Resque
138
141
  :_queue,
139
142
  :create_block,
140
143
  :set_instance,
141
- :_extension=
144
+ :_extension=,
145
+ :_expire_in
142
146
 
143
147
  def_delegators :@cache_file, :filename, :exists?, :ready?
144
148
  def_delegator Const::TO_SUPER, :super_extension
@@ -202,10 +206,11 @@ module Resque
202
206
 
203
207
  def init_cache_file
204
208
  self._extension = super_extension || DEFAULT_EXTENSION
209
+ options = {coding: _encoding, expire_in: _expire_in}
205
210
 
206
211
  @cache_file = CacheFile.new(_directory,
207
212
  generate_filename(@args, _extension),
208
- coding: _encoding)
213
+ options)
209
214
  end
210
215
 
211
216
  # Method specifies how to output report data
@@ -22,7 +22,7 @@ module Resque
22
22
  end
23
23
 
24
24
  def exists?
25
- File.exists?(@filename)
25
+ !expired?(@filename)
26
26
  end
27
27
  alias_method :ready?, :exists?
28
28
 
@@ -75,7 +75,9 @@ module Resque
75
75
  end
76
76
 
77
77
  def expired?(fname)
78
- File.file?(fname) && File.mtime(fname) + @expiration_time < Time.now
78
+ return true unless File.file?(fname)
79
+
80
+ File.mtime(fname) + @expiration_time < Time.now
79
81
  end
80
82
 
81
83
  def cache_files_array
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  module Resque
3
3
  module Reports
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.5'
5
5
  end
6
6
  end
7
7
 
@@ -25,4 +25,5 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency 'rake'
26
26
  gem.add_development_dependency 'rspec', '>= 2.14.0'
27
27
  gem.add_development_dependency 'simplecov'
28
+ gem.add_development_dependency 'timecop', '~> 0.7.1'
28
29
  end
@@ -51,6 +51,22 @@ class MyCsvDefaultsReport < Resque::Reports::CsvReport
51
51
  end
52
52
  end
53
53
 
54
+ class MyCsvExpiredReport < Resque::Reports::CsvReport
55
+ expire_in 3600
56
+ source :select_data
57
+ encoding UTF8
58
+
59
+ directory File.join(Dir.tmpdir, 'resque-reports')
60
+
61
+ table do |element|
62
+ column 'Uno', "#{element} - is value"
63
+ end
64
+
65
+ def select_data
66
+ []
67
+ end
68
+ end
69
+
54
70
  describe 'Resque::Reports::CsvReport successor' do
55
71
  describe '.csv_options' do
56
72
  context 'when custom options not set' do
@@ -90,4 +106,24 @@ describe 'Resque::Reports::CsvReport successor' do
90
106
  end
91
107
  end
92
108
  end
109
+
110
+ describe '#exists?' do
111
+ context 'when report was built' do
112
+ subject { MyCsvExpiredReport.new }
113
+
114
+ before { subject.build }
115
+
116
+ it do
117
+ Timecop.travel(1.hour.since) do
118
+ expect(subject.exists?).to be_false
119
+ end
120
+ end
121
+
122
+ it do
123
+ Timecop.travel(30.minutes.since) do
124
+ expect(subject.exists?).to be_true
125
+ end
126
+ end
127
+ end
128
+ end
93
129
  end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,6 @@ SimpleCov.start
5
5
  require 'rubygems'
6
6
  require 'bundler/setup'
7
7
  require 'rspec'
8
+ require 'timecop'
8
9
 
9
10
  require 'resque-reports'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey D.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque-integration
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.1
97
111
  description: Make your custom reports to CSV in background using Resque with simple
98
112
  DSL
99
113
  email: