Created
June 7, 2017 01:37
-
-
Save StaverDmitry/ed43da82efa482e71e607694029519c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
class ForecastCSV < Struct.new(:forecast, :current_user_id) | |
def perform | |
data = forecast.detect{|f| f[:name] == 'forecast'}[:data] | |
path = "tmp/Forecast-#{Time.now.strftime("%d-%m-%Y %I:%M-%S")}.csv" | |
CSV.open(path, "w+") do |csv| | |
csv << ["date", "value"] | |
data.each do |date, value| | |
csv << [date, value] | |
end | |
end | |
obj = Aws::S3::Resource.new | |
obj = obj.bucket("sail-crm-data").object("reports/Forecast-#{Time.now.strftime("%d-%m-%Y %I:%M-%S")}.csv") | |
obj.upload_file(path, acl:'public-read') | |
Pusher.trigger("crm-user-#{current_user_id}", 'report_download', { | |
message: obj.public_url | |
}) | |
end | |
def after(job) | |
end | |
handle_asynchronously :perform | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment