Skip to content

Commit

Permalink
[WF-401] Workflows: email refactor (#7063)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 3ecb9faaf729b3872beb55bfbb8e2e19f2392df2
  • Loading branch information
sdelany2 authored and Descartes Labs Build committed Jun 15, 2020
1 parent a8265f1 commit 6561a7c
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 77 deletions.
7 changes: 2 additions & 5 deletions descarteslabs/common/proto/destinations/destinations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ message Destination {
message Download {}

message Email {
repeated string to = 1;
repeated string cc = 2;
repeated string bcc = 3;
string subject = 4;
string body = 5;
string subject = 1;
string body = 2;
}
33 changes: 6 additions & 27 deletions descarteslabs/common/proto/destinations/destinations_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

def user_destination_to_proto(params: Union[dict, str]) -> destinations_pb2.Destination:
if isinstance(params, str):
if "@" in params:
params = {"type": "email", "to": params}
else:
params = {"type": params}
params = {"type": params}
else:
if "type" not in params:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
3 changes: 1 addition & 2 deletions descarteslabs/workflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 4 additions & 12 deletions descarteslabs/workflows/docs/destinations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -69,16 +64,13 @@ Examples
Email
~~~~~

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.")

Expand All @@ -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")
2 changes: 1 addition & 1 deletion descarteslabs/workflows/models/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def get_loader(output_destination: destinations_pb2.Destination):

@register(destinations_pb2.Download)
# NOTE(gabe): Disabling email as a downloadable destination for now, because it's confusing
# when `.compute(destination="email@example.com")` returns the data in your notebook.
# when `.compute(destination="email")` returns the data in your notebook.
# Especially if that data is 30mb of binary GeoTIFF dumped into your terminal.
# @register(destinations_pb2.Email)
def download(job: Job):
Expand Down
2 changes: 1 addition & 1 deletion descarteslabs/workflows/models/tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions descarteslabs/workflows/models/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6561a7c

Please sign in to comment.