From 67e97ba4198b32163ac7a7a07c24bae3cc5bed52 Mon Sep 17 00:00:00 2001 From: Blaze <88249929+syncblaze@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:25:45 +0100 Subject: [PATCH] docs: add missing task max_failures/invocations docs (#484) * Update tasks.py * Update loaders.py * Update client.py * Create 484.documentation.md * nox pipeline * british english * Update 484.documentation.md Co-authored-by: nulldomain * Update client.py Co-authored-by: nulldomain * Update loaders.py Co-authored-by: nulldomain * Update tasks.py Co-authored-by: nulldomain --------- Co-authored-by: nulldomain --- fragments/484.documentation.md | 1 + lightbulb/client.py | 3 +++ lightbulb/loaders.py | 3 +++ lightbulb/tasks.py | 3 +++ 4 files changed, 10 insertions(+) create mode 100644 fragments/484.documentation.md diff --git a/fragments/484.documentation.md b/fragments/484.documentation.md new file mode 100644 index 00000000..11bd6237 --- /dev/null +++ b/fragments/484.documentation.md @@ -0,0 +1 @@ +Document the behaviour of `max_failures` and `max_invocations` in tasks and how to disable each. diff --git a/lightbulb/client.py b/lightbulb/client.py index 771685a4..8db9b540 100644 --- a/lightbulb/client.py +++ b/lightbulb/client.py @@ -332,7 +332,10 @@ def task( # noqa: D417 the client upon the client being started, the task will also be started; it will also be started if being added to an already-started client. max_failures: The maximum number of failed attempts to execute the task before it is cancelled. + Setting this to a negative number will prevent the task from being cancelled, regardless of + how often the task fails. max_invocations: The maximum number of times the task can be invoked before being stopped. + Setting this to a negative number will disable this behaviour, allowing unlimited invocations. Note: This method can also be called with an existing task object to register it directly. diff --git a/lightbulb/loaders.py b/lightbulb/loaders.py index 79d431f8..ceb3b07a 100644 --- a/lightbulb/loaders.py +++ b/lightbulb/loaders.py @@ -400,7 +400,10 @@ def task( the client upon the client being started, the task will also be started; it will also be started if being added to an already-started client. max_failures: The maximum number of failed attempts to execute the task before it is cancelled. + Setting this to a negative number will prevent the task from being cancelled, regardless of + how often the task fails. max_invocations: The maximum number of times the task can be invoked before being stopped. + Setting this to a negative number will disable this behaviour, allowing unlimited invocations. Example: diff --git a/lightbulb/tasks.py b/lightbulb/tasks.py index eccfe3c3..7298c13f 100644 --- a/lightbulb/tasks.py +++ b/lightbulb/tasks.py @@ -223,7 +223,10 @@ class Task: the client upon the client being started, the task will also be started; it will also be started if being added to an already-started client. max_failures: The maximum number of failed attempts to execute the task before it is cancelled. + Setting this to a negative number will prevent the task from being cancelled, regardless of + how often the task fails. max_invocations: The maximum number of times the task can be invoked before being stopped. + Setting this to a negative number will disable this behaviour, allowing unlimited invocations. """ __slots__ = [