This is an automated email from the ASF dual-hosted git repository.

sjwiesman pushed a commit to branch release-2.1
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git


The following commit(s) were added to refs/heads/release-2.1 by this push:
     new c086d85  [hotfix] fix python sdk example
c086d85 is described below

commit c086d85ca07a414eb6ab52223cd0d64110e03bf3
Author: Seth Wiesman <sjwies...@gmail.com>
AuthorDate: Mon Aug 3 17:45:36 2020 -0500

    [hotfix] fix python sdk example
---
 docs/sdk/python.md | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/docs/sdk/python.md b/docs/sdk/python.md
index 4cfd1e3..ed74c30 100644
--- a/docs/sdk/python.md
+++ b/docs/sdk/python.md
@@ -132,23 +132,23 @@ The delayed message is non-blocking so functions will 
continue to process record
 The delay is specified via a [Python 
timedelta](https://docs.python.org/3/library/datetime.html#datetime.timedelta).
 
 {% highlight python %}
-from google.protobuf.any_pb2 import Any
+from datetime import timedelta
 from statefun import StatefulFunctions
 
 functions = StatefulFunctions()
 
-@functions.bind("example/caller")
-def caller_function(context, message):
-    """A simple stateful function that sends a message to the user with id 
`user1`"""
+@functions.bind("example/delay")
+def delayed_function(context, message):
+    """A simple stateful function that sends a message to its caller with a 
delay"""
 
-    user = User()
-    user.user_id = "user1"
-    user.name = "Seth"
+    response = Response()
+    response.message = "hello from the past"
 
-    envelope = Any()
-    envelope.Pack(user)
-
-    context.send("example/hello", user.user_id, envelope)
+    context.pack_and_send_after(
+        context.caller.typename(), 
+        context.caller.identity,
+        timedelta(minutes=30),
+        response)
 {% endhighlight %}
 
 ## Persistence
@@ -243,6 +243,10 @@ if __name__ == "__main__":
 
 The ``context`` object passed to each function has the following attributes / 
methods.
 
+* address 
+    * The address of the current function under execution
+* caller
+    * The address of the function that sent the current message. May be 
``None`` if the message came from an ingress.
 * send(self, typename: str, id: str, message: Any)
     * Send a message to any function with the function type of the the form 
``<namesapce>/<type>`` and message of type ``google.protobuf.Any``
 * pack_and_send(self, typename: str, id: str, message)

Reply via email to