resque-reports 0.4.4 → 0.4.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 +8 -8
- data/Gemfile +1 -1
- data/lib/resque/reports/base_report.rb +8 -3
- data/lib/resque/reports/cache_file.rb +4 -2
- data/lib/resque/reports/version.rb +1 -1
- data/resque-reports.gemspec +1 -0
- data/spec/resque/reports/csv_report_spec.rb +36 -0
- data/spec/spec_helper.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTg1YTcwMDRhNWJhYTViN2I1NjVmYzMxODQwNjBjNmZlZGEyNDg2Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWY4NWZhNzZlN2MyNmYzMjVlMWU0ODA0M2Q2M2E4Mjg5ZmJjZjE4Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTYyN2UxMzVlMDJlYWYyZjU0Yzc4ODE0NWQ3YzY1ZDQwZDdiZDY0MGMzYWJh
|
10
|
+
YzYyMmRiZjQ3N2U1ZjIzMjAzMDU2ZDQ3ZDFkY2RlNmVhMzAwZmRlZTkxNzEw
|
11
|
+
MDMxYWU1YmJjMmRiYzZkN2VmODVjZmIxMGJiYTg0YmQ0YTAzYjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGYwN2RhZGFiZWMxYzQyMTAyMzY5YWJmNGMwY2NjZjA2NzIyYTA4NGY2YzA3
|
14
|
+
NjliYmU2ZmEzOTU4MzViODNiNjhlMDJiZTNiNWEwNTQxZWNjMDc2MTM3ZjVi
|
15
|
+
Zjk2ZWU2YWI0ZWU2MzAyZGVjNGQ0MGUxNTA0NTYyMjMyYzlhZDQ=
|
data/Gemfile
CHANGED
@@ -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
|
-
|
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
|
-
|
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)
|
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
|
data/resque-reports.gemspec
CHANGED
@@ -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
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
|
+
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-
|
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:
|