-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Activations counter | ||
|
||
---- | ||
## Overview | ||
|
||
This project provides a solution to notifying a TD user by email that the last 3 activation attempts of a given activation have not activated any records. | ||
Simply change the code to adjust the attempt count or the activated record count. | ||
|
||
---- | ||
## Implementation | ||
1. Copy and paste the code into a custom script in Treasure Workflows. | ||
|
||
---- | ||
## Considerations | ||
|
||
N/A | ||
|
||
---- | ||
## Questions | ||
|
||
Please feel free to reach out to [email protected] with any questions you have about using this code. |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
timezone: Asia/Tokyo | ||
|
||
_export: | ||
td: | ||
database: activation_counter_db | ||
table: activation_counter_tbl | ||
|
||
+echo_activation_actions_parameters: | ||
echo>: segment_id ==> ${segment_id}, segment_name ==> ${segment_name}, activation_id ==> ${activation_id}, audience_id ==> ${audience_id} | ||
|
||
+register_count: | ||
td>: queries/count_activated_records.sql | ||
insert_into: ${td.table} | ||
database: ${td.database} | ||
|
||
+check_counts: | ||
td>: queries/check_counts.sql | ||
database: ${td.database} | ||
store_last_results: true | ||
|
||
+send_email: | ||
if>: ${td.last_results.cnt == 3 && td.last_results.sum == 0} | ||
_do: | ||
mail>: notifications/email.txt | ||
subject: "Treasure Data Activation ${td.last_results.act_id} warning" | ||
to: [[email protected]] | ||
html: true | ||
+sent: | ||
echo>: Email sent! |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<html> | ||
<body> | ||
<head> | ||
<style> | ||
/* Reset styles */ | ||
body, | ||
h1, | ||
p { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
font-family: Arial, sans-serif; | ||
line-height: 1.6; | ||
background-color: #f9f9f9; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
/* Footer styles */ | ||
.footer { | ||
text-align: center; | ||
padding: 20px 0; | ||
background-color: #007bff; | ||
color: #fff; | ||
} | ||
|
||
.footer p { | ||
font-size: 14px; | ||
} | ||
/* Button styles */ | ||
.button { | ||
display: inline-block; | ||
background-color: #ffffff; | ||
color: #fff; | ||
text-decoration: none; | ||
padding: 10px 20px; | ||
border-radius: 5px; | ||
font-weight: bold; | ||
margin: 30px auto; | ||
} | ||
</style> | ||
</head> | ||
<h1>Treasure Data Activation ${td.last_results.act_id} has not syndicated a single record during its 3 previous runs.</h1> | ||
<h2><a href="https://console-next.treasuredata.com/app/ps/${audience_id}/e/${segment_id}/sb/ac/${activation_id}/ea" class="button">Visit the Activation</a></h2> | ||
<div class="footer"> | ||
<p>This email was sent automatically. Please do not reply.</p> | ||
</div> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SELECT | ||
act_id, | ||
SUM(rec_cnt) AS "sum", | ||
COUNT(1) AS cnt | ||
FROM | ||
( | ||
SELECT | ||
act_id, | ||
rec_cnt | ||
FROM | ||
${td.table} | ||
WHERE | ||
act_id = ${activation_id} | ||
ORDER BY | ||
time DESC | ||
LIMIT 3 | ||
) | ||
GROUP BY | ||
act_id |
5 changes: 5 additions & 0 deletions
5
scenarios/activations_counter/queries/count_activated_records.sql
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SELECT | ||
COUNT(1) AS rec_cnt, | ||
${activation_id} AS act_id | ||
FROM | ||
${activation_actions_db}.${activation_actions_table} |