File tree Expand file tree Collapse file tree 2 files changed +24
-30
lines changed Expand file tree Collapse file tree 2 files changed +24
-30
lines changed Original file line number Diff line number Diff line change 1
1
module Statistics
2
2
class Client
3
- class APIRateLimitError < ::StandardError ; end
4
-
5
3
class_attribute :debug
6
4
self . debug = false
7
5
@@ -81,31 +79,34 @@ def search(keyword:)
81
79
end
82
80
83
81
def fetch_events ( group_id :, since_at : @default_since , until_at : @default_until )
84
- params = {
85
- page : 1 ,
86
- since : since_at ,
87
- until : until_at
88
- }
89
- events = [ ]
82
+ begin
83
+ params = {
84
+ page : 1 ,
85
+ since : since_at ,
86
+ until : until_at
87
+ }
88
+ events = [ ]
90
89
91
- loop do
92
- part = @client . get ( "groups/#{ group_id } /events" , params )
90
+ loop do
91
+ part = @client . get ( "groups/#{ group_id } /events" , params )
93
92
94
- break if part . size . zero?
93
+ break if part . size . zero?
95
94
96
- events . push ( *part . map { |e | e [ 'event' ] } )
95
+ events . push ( *part . map { |e | e [ 'event' ] } )
97
96
98
- break if part . size < 25 # 25 items / 1 request
97
+ break if part . size < 25 # 25 items / 1 request
99
98
100
- params [ :page ] += 1
101
- end
99
+ params [ :page ] += 1
100
+ end
102
101
103
- events
104
- rescue Faraday ::ClientError => e
105
- if e . response [ :status ] == 429
106
- raise Client ::APIRateLimitError
107
- else
108
- raise e
102
+ events
103
+ rescue Faraday ::ClientError => e
104
+ raise e unless e . response [ :status ] == 429
105
+
106
+ puts 'API rate limit exceeded.'
107
+ puts "This task will retry in 60 seconds from now(#{ Time . zone . now } )."
108
+ sleep 60
109
+ retry
109
110
end
110
111
end
111
112
end
Original file line number Diff line number Diff line change @@ -44,15 +44,8 @@ namespace :statistics do
44
44
raise StopIteration if nm > to
45
45
list << nm
46
46
} . each { |date |
47
- begin
48
- puts "Aggregate for #{ date . strftime ( '%Y/%m' ) } "
49
- Statistics ::Aggregation . run ( date : date )
50
- rescue Statistics ::Client ::APIRateLimitError
51
- puts 'API rate limit exceeded.'
52
- puts "This task will retry in 60 seconds from now(#{ Time . zone . now } )."
53
- sleep 60
54
- retry
55
- end
47
+ puts "Aggregate for #{ date . strftime ( '%Y/%m' ) } "
48
+ Statistics ::Aggregation . run ( date : date )
56
49
}
57
50
end
58
51
You can’t perform that action at this time.
0 commit comments