Skip to content

Commit 6d3c097

Browse files
authored
Merge pull request #396 from coderdojo-japan/mod_aggregation_message
イベント履歴収集スクリプトでプロバイダ指定したとき、成功/失敗のメッセージにプロバイダを含める
2 parents d30708b + adda841 commit 6d3c097

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/statistics/aggregation.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module Statistics
22
class Aggregation
33
def initialize(args)
44
@from, @to = aggregation_period(args[:from], args[:to])
5-
dojos = fetch_dojos(args[:provider])
5+
@provider = args[:provider]
6+
dojos = fetch_dojos(@provider)
67
@externals = dojos[:externals]
78
@internals = dojos[:internals]
89
end
@@ -86,9 +87,9 @@ def find_dojos_by(services)
8687

8788
def with_notifying
8889
yield
89-
Notifier.notify_success(date_format(@from), date_format(@to))
90+
Notifier.notify_success(date_format(@from), date_format(@to), @provider)
9091
rescue => e
91-
Notifier.notify_failure(date_format(@from), date_format(@to), e)
92+
Notifier.notify_failure(date_format(@from), date_format(@to), @provider, e)
9293
end
9394

9495
def delete_event_histories
@@ -119,16 +120,20 @@ def date_format(date)
119120

120121
class Notifier
121122
class << self
122-
def notify_success(from, to)
123-
notify("#{from}~#{to}のイベント履歴の集計を行いました")
123+
def notify_success(from, to, provider)
124+
notify("#{from}~#{to}#{provider_info(provider)}のイベント履歴の集計を行いました")
124125
end
125126

126-
def notify_failure(from, to, exception)
127-
notify("#{from}~#{to}のイベント履歴の集計でエラーが発生しました\n#{exception.message}\n#{exception.backtrace.join("\n")}")
127+
def notify_failure(from, to, provider, exception)
128+
notify("#{from}~#{to}#{provider_info(provider)}のイベント履歴の集計でエラーが発生しました\n#{exception.message}\n#{exception.backtrace.join("\n")}")
128129
end
129130

130131
private
131132

133+
def provider_info(provider)
134+
provider ? "(#{provider})" : nil
135+
end
136+
132137
def idobata_hook_url
133138
return @idobata_hook_url if defined?(@idobata_hook_url)
134139
@idobata_hook_url = ENV['IDOBATA_HOOK_URL']

0 commit comments

Comments
 (0)