You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by sj...@apache.org on 2020/08/04 16:53:54 UTC
[flink-statefun] branch master updated: [hotfix] fix python sdk
example
This is an automated email from the ASF dual-hosted git repository.
sjwiesman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git
The following commit(s) were added to refs/heads/master by this push:
new 70646bf [hotfix] fix python sdk example
70646bf is described below
commit 70646bf1c9c20c9a9807f02e4d5443208e59316b
Author: Seth Wiesman <sj...@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)