Skip to content

Commit cca2f3a

Browse files
committed
Notify to idobata when task is finished
1 parent a7da867 commit cca2f3a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/tasks/statistics.rake

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ namespace :statistics do
1616
d
1717
}
1818

19+
notify_idobata = -> (msg) {
20+
puts `curl --data-urlencode "source=#{msg}" -s #{ENV['IDOBATA_HOOK_URL']} -o /dev/null -w "idobata: %{http_code}"` if ENV.key?('IDOBATA_HOOK_URL')
21+
}
22+
1923
from = if args[:from]
2024
if args[:from].length == 4
2125
date_from_str.call(args[:from]).beginning_of_year
@@ -39,14 +43,20 @@ namespace :statistics do
3943

4044
EventHistory.where(evented_at: from..to).delete_all
4145

42-
loop.with_object([from]) { |_, list|
43-
nm = list.last.next_month
44-
raise StopIteration if nm > to
45-
list << nm
46-
}.each { |date|
47-
puts "Aggregate for #{date.strftime('%Y/%m')}"
48-
Statistics::Aggregation.run(date: date)
49-
}
46+
begin
47+
loop.with_object([from]) { |_, list|
48+
nm = list.last.next_month
49+
raise StopIteration if nm > to
50+
list << nm
51+
}.each { |date|
52+
puts "Aggregate for #{date.strftime('%Y/%m')}"
53+
Statistics::Aggregation.run(date: date)
54+
}
55+
56+
notify_idobata.call("#{from.strftime('%Y/%m')}~#{to.strftime('%Y/%m')}のイベント履歴の集計を行いました")
57+
rescue
58+
notify_idobata.call("#{from.strftime('%Y/%m')}~#{to.strftime('%Y/%m')}のイベント履歴の集計でエラーが発生しました")
59+
end
5060
end
5161

5262
desc 'キーワードからイベント情報を検索します'

0 commit comments

Comments
 (0)