-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* encode/decode date range in filenames * Update lib/plausible/imported/csv_importer.ex Co-authored-by: Adrian Gruntkowski <[email protected]> * Update lib/plausible/imported/csv_importer.ex Co-authored-by: Adrian Gruntkowski <[email protected]> * drop unused functions * send failure email if there is no data to export * use PlausibleWeb.Email.mailer_email_from() * ensure we get dates from minmax date query --------- Co-authored-by: Adrian Gruntkowski <[email protected]>
- Loading branch information
1 parent
4242b52
commit 279e89c
Showing
9 changed files
with
292 additions
and
127 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,43 +25,56 @@ defmodule Plausible.Workers.ExportCSV do | |
|> Keyword.replace!(:pool_size, 1) | ||
|> Ch.start_link() | ||
|
||
# NOTE: should we use site.timezone? | ||
# %Ch.Result{rows: [[min_date, max_date]]} = | ||
# Ch.query!( | ||
# ch, | ||
# "SELECT toDate(min(timestamp)), toDate(max(timestamp)) FROM events_v2 WHERE site_id={site_id:UInt64}", | ||
# %{"site_id" => site_id} | ||
# ) | ||
|
||
download_url = | ||
DBConnection.run( | ||
%Ch.Result{rows: [[%Date{} = min_date, %Date{} = max_date]]} = | ||
Ch.query!( | ||
ch, | ||
fn conn -> | ||
conn | ||
|> Plausible.Exports.stream_archive( | ||
# date_range: Date.range(min_date, max_date) | ||
Plausible.Exports.export_queries(site_id, extname: ".csv"), | ||
format: "CSVWithNames" | ||
) | ||
|> Plausible.S3.export_upload_multipart(s3_bucket, s3_path, s3_config_overrides(args)) | ||
end, | ||
timeout: :infinity | ||
"SELECT toDate(min(timestamp)), toDate(max(timestamp)) FROM events_v2 WHERE site_id={site_id:UInt64}", | ||
%{"site_id" => site_id} | ||
) | ||
|
||
if max_date == ~D[1970-01-01] do | ||
# NOTE: replace with proper Plausible.Email template | ||
Plausible.Mailer.deliver_now!( | ||
Bamboo.Email.new_email( | ||
from: PlausibleWeb.Email.mailer_email_from(), | ||
to: email, | ||
subject: "EXPORT FAILURE", | ||
text_body: "there is nothing to export" | ||
) | ||
) | ||
else | ||
download_url = | ||
DBConnection.run( | ||
ch, | ||
fn conn -> | ||
conn | ||
|> Plausible.Exports.stream_archive( | ||
Plausible.Exports.export_queries(site_id, | ||
date_range: Date.range(min_date, max_date), | ||
extname: ".csv" | ||
), | ||
format: "CSVWithNames" | ||
) | ||
|> Plausible.S3.export_upload_multipart(s3_bucket, s3_path, s3_config_overrides(args)) | ||
end, | ||
timeout: :infinity | ||
) | ||
|
||
# NOTE: replace with proper Plausible.Email template | ||
Plausible.Mailer.deliver_now!( | ||
Bamboo.Email.new_email( | ||
from: "[email protected]", | ||
to: email, | ||
subject: "EXPORT SUCCESS", | ||
text_body: """ | ||
download it from #{download_url}! hurry up! you have 24 hours!" | ||
""", | ||
html_body: """ | ||
download it from <a href="#{download_url}">here</a>! hurry up! you have 24 hours! | ||
""" | ||
# NOTE: replace with proper Plausible.Email template | ||
Plausible.Mailer.deliver_now!( | ||
Bamboo.Email.new_email( | ||
from: PlausibleWeb.Email.mailer_email_from(), | ||
to: email, | ||
subject: "EXPORT SUCCESS", | ||
text_body: """ | ||
download it from #{download_url}! hurry up! you have 24 hours!" | ||
""", | ||
html_body: """ | ||
download it from <a href="#{download_url}">here</a>! hurry up! you have 24 hours! | ||
""" | ||
) | ||
) | ||
) | ||
end | ||
|
||
:ok | ||
end | ||
|
Oops, something went wrong.