notice

This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).

Version: Main/Unreleased

rasa.core.lock_store

LockError Objects

class LockError(RasaException)

Exception that is raised when a lock cannot be acquired.

Attributes:

  • message str - explanation of which conversation_id raised the error

LockStore Objects

class LockStore()

Base class for ticket locks.

create

@staticmethod
def create(obj: Union[LockStore, EndpointConfig, None]) -> LockStore

Factory to create a lock store.

create_lock

@staticmethod
def create_lock(conversation_id: Text) -> TicketLock

Create a new TicketLock for conversation_id.

get_lock

def get_lock(conversation_id: Text) -> Optional[TicketLock]

Fetch lock for conversation_id from storage.

delete_lock

def delete_lock(conversation_id: Text) -> None

Delete lock for conversation_id from storage.

save_lock

def save_lock(lock: TicketLock) -> None

Commit lock to storage.

issue_ticket

def issue_ticket(conversation_id: Text,
lock_lifetime: float = LOCK_LIFETIME) -> int

Issue new ticket with lock_lifetime for lock associated with conversation_id.

Creates a new lock if none is found.

lock

@asynccontextmanager
async def lock(
conversation_id: Text,
lock_lifetime: float = LOCK_LIFETIME,
wait_time_in_seconds: float = 1) -> AsyncGenerator[TicketLock, None]

Acquire lock with lifetime lock_lifetimefor conversation_id.

Try acquiring lock with a wait time of wait_time_in_seconds seconds between attempts. Raise a LockError if lock has expired.

update_lock

def update_lock(conversation_id: Text) -> None

Fetch lock for conversation_id, remove expired tickets and save lock.

get_or_create_lock

def get_or_create_lock(conversation_id: Text) -> TicketLock

Fetch existing lock for conversation_id.

Alternatively, create a new one if it doesn't exist.

is_someone_waiting

def is_someone_waiting(conversation_id: Text) -> bool

Return whether someone is waiting for lock for this conversation_id.

finish_serving

def finish_serving(conversation_id: Text, ticket_number: int) -> None

Finish serving ticket with ticket_number for conversation_id.

Removes ticket from lock and saves lock.

cleanup

def cleanup(conversation_id: Text, ticket_number: int) -> None

Remove lock for conversation_id if no one is waiting.

RedisLockStore Objects

class RedisLockStore(LockStore)

Redis store for ticket locks.

__init__

def __init__(
host: Text = "localhost",
port: int = 6379,
db: int = 1,
username: Optional[Text] = None,
password: Optional[Text] = None,
use_ssl: bool = False,
ssl_certfile: Optional[Text] = None,
ssl_keyfile: Optional[Text] = None,
ssl_ca_certs: Optional[Text] = None,
key_prefix: Optional[Text] = None,
socket_timeout: float = DEFAULT_SOCKET_TIMEOUT_IN_SECONDS) -> None

Create a lock store which uses Redis for persistence.

Arguments:

  • host - The host of the redis server.
  • port - The port of the redis server.
  • db - The name of the database within Redis which should be used by Rasa Open Source.
  • username - The username which should be used for authentication with the Redis database.
  • password - The password which should be used for authentication with the Redis database.
  • use_ssl - True if SSL should be used for the connection to Redis.
  • ssl_certfile - Path to the SSL certificate file.
  • ssl_keyfile - Path to the SSL private key file.
  • ssl_ca_certs - Path to the SSL CA certificate file.
  • port0 - prefix to prepend to all keys used by the lock store. Must be alphanumeric.
  • port1 - Timeout in seconds after which an exception will be raised in case Redis doesn't respond within port1 seconds.

get_lock

def get_lock(conversation_id: Text) -> Optional[TicketLock]

Retrieves lock (see parent docstring for more information).

delete_lock

def delete_lock(conversation_id: Text) -> None

Deletes lock for conversation ID.

InMemoryLockStore Objects

class InMemoryLockStore(LockStore)

In-memory store for ticket locks.

__init__

def __init__() -> None

Initialise dictionary of locks.

get_lock

def get_lock(conversation_id: Text) -> Optional[TicketLock]

Get lock for conversation if it exists.

delete_lock

def delete_lock(conversation_id: Text) -> None

Delete lock for conversation.

save_lock

def save_lock(lock: TicketLock) -> None

Save lock in store.