From 97d0f5985230cbad63a1a6cc8283666e0a291f19 Mon Sep 17 00:00:00 2001 From: Kale Blankenship Date: Tue, 19 Jan 2016 13:37:28 -0800 Subject: [PATCH 1/2] Update documentation for Python action datastore access * This documents the changes in stackstorm/st2#2396 --- docs/source/actions.rst | 26 ++++++++++++++++++++++++++ docs/source/sensors.rst | 2 ++ 2 files changed, 28 insertions(+) diff --git a/docs/source/actions.rst b/docs/source/actions.rst index 11d0534f7..981436a72 100644 --- a/docs/source/actions.rst +++ b/docs/source/actions.rst @@ -543,6 +543,32 @@ For example: else: self.logger.error('Action failed...') +Datastore +~~~~~~~~~ + +Actions can utilize the datastore to store data between executions. + +The datastore service provides the same methods available on the sensor service. +More detail can be found in the :ref:`sensor datastore management documentation`. + +Example storing a dict as JSON: + +.. sourcecode:: python + + def run(self): + data = {'somedata': 'foobar'} + + # Add a value to the datastore + self.datastore.set_value(name='cache', value=json.dumps(data)) + + # Retrieve a value + value = self.datastore.get_value('cache') + retrieved_data = json.loads(value) + + # Delete a value + self.datastore.delete_value('cache') + + Pre-defined actions ^^^^^^^^^^^^^^^^^^^ diff --git a/docs/source/sensors.rst b/docs/source/sensors.rst index fcf8b4a0f..123a6abb9 100644 --- a/docs/source/sensors.rst +++ b/docs/source/sensors.rst @@ -116,6 +116,8 @@ For example: self._logger = self._sensor_service.get_logger(name=self.__class__.__name__) self._logger.debug('Polling 3rd party system for information') +.. _ref-sensors-datastore-management-operations + Datastore management operations ------------------------------- From 7ba4cb123f946a0eaac92bd6ec8c791e73641426 Mon Sep 17 00:00:00 2001 From: Kale Blankenship Date: Wed, 3 Feb 2016 12:35:05 -0800 Subject: [PATCH 2/2] Update sensors.rst --- docs/source/sensors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/sensors.rst b/docs/source/sensors.rst index 123a6abb9..2bc9c530c 100644 --- a/docs/source/sensors.rst +++ b/docs/source/sensors.rst @@ -116,7 +116,7 @@ For example: self._logger = self._sensor_service.get_logger(name=self.__class__.__name__) self._logger.debug('Polling 3rd party system for information') -.. _ref-sensors-datastore-management-operations +.. _ref-sensors-datastore-management-operations: Datastore management operations -------------------------------