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..2bc9c530c 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 -------------------------------