-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WF-401] Workflows: email refactor (#7063)
GitOrigin-RevId: 3ecb9faaf729b3872beb55bfbb8e2e19f2392df2
- Loading branch information
Showing
10 changed files
with
21 additions
and
77 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
33 changes: 6 additions & 27 deletions
33
descarteslabs/common/proto/destinations/destinations_pb2.py
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -23,14 +23,7 @@ | |
), | ||
({"type": "download"}, destinations_pb2.Destination), | ||
( | ||
{ | ||
"type": "email", | ||
"to": ["[email protected]", "[email protected]"], | ||
"cc": ["[email protected]", "[email protected]"], | ||
"bcc": ["[email protected]", "[email protected]"], | ||
"subject": "This is a test", | ||
"body": "Testing", | ||
}, | ||
{"type": "email", "subject": "This is a test", "body": "Testing"}, | ||
destinations_pb2.Destination, | ||
), | ||
], | ||
|
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 |
---|---|---|
|
@@ -20,35 +20,23 @@ def test_user_dict_to_has_proto(): | |
) | ||
|
||
proto = user_dict_to_has_proto( | ||
{"type": "email", "to": "[email protected]", "subject": 1234}, | ||
destinations_pb2.Destination, | ||
{}, | ||
{"type": "email", "subject": 1234}, destinations_pb2.Destination, {} | ||
) | ||
assert isinstance(proto, destinations_pb2.Destination) | ||
assert proto.has_email and not proto.has_download | ||
assert proto.email.to == ["[email protected]"] | ||
assert proto.email.cc == [] | ||
assert proto.email.bcc == [] | ||
assert proto.email.subject == "1234" | ||
assert proto.email.body == "" | ||
|
||
|
||
def test_user_dict_to_has_proto_defaults(): | ||
defaults = { | ||
"to": ["foo", "bar"], | ||
"bcc": "[email protected]", | ||
"body": "job is done", | ||
} | ||
defaults = {"body": "job is done"} | ||
proto = user_dict_to_has_proto( | ||
{"type": "email", "to": "[email protected]"}, | ||
{"type": "email"}, | ||
destinations_pb2.Destination, | ||
{destinations_pb2.Email: defaults}, | ||
) | ||
assert isinstance(proto, destinations_pb2.Destination) | ||
assert proto.has_email and not proto.has_download | ||
assert proto.email.to == ["[email protected]"] | ||
assert proto.email.cc == [] | ||
assert proto.email.bcc == [defaults["bcc"]] | ||
assert proto.email.subject == "" | ||
assert proto.email.body == defaults["body"] | ||
|
||
|
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 |
---|---|---|
|
@@ -188,13 +188,12 @@ def compute( | |
>>> wf.compute(num, destination="download") # default # doctest: +SKIP | ||
2 | ||
>>> # same computation but with email destination | ||
>>> wf.compute(num, destination="example@email.com") # doctest: +SKIP | ||
>>> wf.compute(num, destination="email") # doctest: +SKIP | ||
>>> # now with some destination options | ||
>>> wf.compute( | ||
... num, | ||
... destination={ | ||
... "type": "email", | ||
... "to": "[email protected]", | ||
... "subject": "My Computation is Done" | ||
... }, | ||
... format="json", | ||
|
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 |
---|---|---|
|
@@ -24,15 +24,10 @@ If you don't need to supply any options for the destination, you can pass the de | |
>>> two = wf.Int(1) + 1 | ||
>>> two.compute(destination="download") | ||
|
||
For the email destination, you can pass the receiver's email address as a string for convenience:: | ||
|
||
>>> two = wf.Int(1) + 1 | ||
>>> two.compute(destination="[email protected]") | ||
|
||
If you would like to provide more destination options, you pass the destination as a dictionary:: | ||
|
||
>>> two = wf.Int(1) + 1 | ||
>>> two.compute(destination={"type": "email", "to": "[email protected]", "subject": "My Computation is Done"}) | ||
>>> two.compute(destination={"type": "email", "subject": "My Computation is Done"}) | ||
|
||
Note that when passing the destination as a dictionary, it must include a ``type`` key corresponding to the desired destination. | ||
|
||
|
@@ -69,16 +64,13 @@ Examples | |
~~~~~ | ||
|
||
Shorthand: an email address, like ``"example@email.com"`` | ||
Shorthand: ``"email"`` | ||
|
||
Email is equivalent to `Download`_, but also sends an email when the job is done. The email contains a link to download the data. Anyone with that link can download the data. As with `Download`_, the link will expire after 10 days. | ||
|
||
Options | ||
******* | ||
|
||
- ``to``: the email address to send the email to (string or list of strings) | ||
- ``cc``: the email address to cc on the email (string or list of strings) | ||
- ``bcc``: the email address to bcc on the email (string or list of strings) | ||
- ``subject``: the subject of the email (string, default "Your job has completed"). Always prefixed with ``Workflows:``. | ||
- ``body``: the body of the email (string, default "Your Workflows job is done.") | ||
|
||
|
@@ -90,7 +82,7 @@ Compatible Formats | |
Examples | ||
******** | ||
>>> two = wf.Int(1) + 1 | ||
>>> two.compute(destination="example@email.com", format="json") | ||
>>> two.compute(destination="email", format="json") | ||
|
||
>>> two = wf.Int(1) + 1 | ||
>>> two.compute(destination={"type": "email", "to": "[email protected]", "subject": "My Computation is Done"}, format="json") | ||
>>> two.compute(destination={"type": "email", "subject": "My Computation is Done"}, format="json") |
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 |
---|---|---|
|
@@ -209,7 +209,7 @@ def test_properties(self, stub): | |
obj = types.Int(1) | ||
parameters = {"foo": types.Str("bar")} | ||
format = "geotiff" | ||
destination = {"type": "email", "to": "[email protected]"} | ||
destination = {"type": "email"} | ||
|
||
job_state = job_pb2.Job.State(stage=job_pb2.Job.Stage.QUEUED) | ||
|
||
|
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 |
---|---|---|
|
@@ -101,13 +101,12 @@ def compute( | |
>>> wf.compute(num, destination="download") # default # doctest: +SKIP | ||
2 | ||
>>> # same computation but with email destination | ||
>>> wf.compute(num, destination="example@email.com") # doctest: +SKIP | ||
>>> wf.compute(num, destination="email") # doctest: +SKIP | ||
>>> # now with some destination options | ||
>>> wf.compute( | ||
... num, | ||
... destination={ | ||
... "type": "email", | ||
... "to": "[email protected]", | ||
... "subject": "My Computation is Done" | ||
... }, | ||
... format="json", | ||
|