Background Task Builders¶
Chainable builders for server-side background operations on datasets.
- class aerospike_sdk.aio.background.BackgroundTaskSession[source]¶
Bases:
objectChoose a dataset-wide background job (update, delete, touch, or UDF).
From
background_task(). Each method returns a builder to add filters, bin operations or UDF arguments, thenawait ...execute()for a serverExecuteTask.Example
Background update with a filter:
task = await ( session.background_task() .update(users) .where("$.active == true") .bin("score").add(1) .execute() )
See also
execute_udf(): Foreground UDF on keys.- update(dataset)[source]¶
Start a
query_operateupdate over records in dataset.- Parameters:
dataset (
DataSet) – Namespace/set scope for the scan.- Return type:
- Returns:
BackgroundOperationBuilder— addwhere,bin, thenBackgroundOperationBuilder.execute().- Raises:
ValueError – On execute if no bin operations were added.
- delete(dataset)[source]¶
Start a background delete of all records matching optional filters.
- Parameters:
dataset (
DataSet) – Namespace/set to scan.- Return type:
- Returns:
BackgroundOperationBuilder(no bin ops required for delete).
- touch(dataset)[source]¶
Start a background touch (TTL refresh) for matching records.
- Parameters:
dataset (
DataSet) – Namespace/set to scan.- Return type:
- Returns:
BackgroundOperationBuilder— optionalexpire_record_after_seconds.
- execute_udf(dataset)[source]¶
Start a background UDF executed via
query_execute_udf.- Parameters:
dataset (
DataSet) – Namespace/set scope.- Return type:
- Returns:
BackgroundUdfFunctionBuilder— callBackgroundUdfFunctionBuilder.function()thenBackgroundUdfBuilder.passing()andBackgroundUdfBuilder.execute().
- class aerospike_sdk.aio.background.BackgroundWriteBinBuilder[source]¶
Bases:
objectPer-bin write helper for background updates (
put/addonly).Obtained from
BackgroundOperationBuilder.bin(). Callset_to()oradd(), which return the parent builder for further chaining.Example:
builder.bin("score").add(10)
- __init__(parent, bin_name)[source]¶
Capture the bin name; prefer
BackgroundOperationBuilder.bin().
- set_to(value)[source]¶
Set the bin to value (
Operation.put).- Parameters:
value (
Any) – The value to write.- Return type:
- Returns:
The parent
BackgroundOperationBuilder.
- add(value)[source]¶
Add a numeric value to the bin (
Operation.add).- Parameters:
value (
Any) – Numeric amount to add (may be negative).- Return type:
- Returns:
The parent
BackgroundOperationBuilder.
- class aerospike_sdk.aio.background.BackgroundOperationBuilder[source]¶
Bases:
objectConfigure filters, TTL, and operations for
query_operate.Not all query-policy knobs are wired through to PAC for background jobs;
records_per_secondis stored for API parity but may not affect the underlying call.See also
BackgroundTaskSession.update(): Typical construction path.- where(expression)[source]¶
- Overloads:
self, expression (str) → BackgroundOperationBuilder
self, expression (FilterExpression) → BackgroundOperationBuilder
Restrict the scan with an AEL or
FilterExpressionpredicate.- Returns:
This builder for chaining.
- Example::
builder.where(“$.status == ‘inactive’”)
- bin(name)[source]¶
Start a scalar write on name (update jobs only).
- Return type:
- Example::
builder.bin(“score”).add(10)
- expire_record_after_seconds(seconds)[source]¶
Set record TTL in seconds for touches/updates when supported by policy.
- Return type:
- records_per_second(rps)[source]¶
Store a throttle hint (may be unused depending on PAC background API).
- Return type:
- async execute()[source]¶
Start the server job and return an
ExecuteTask.- Raises:
ValueError – For update without bin operations.
RuntimeError – If the SDK client is not connected.
AerospikeError – On PAC errors (converted).
Example:
task = await ( session.background_task() .update(users) .bin("visits").add(1) .execute() ) await task.wait_till_complete()
- Return type:
ExecuteTask
- class aerospike_sdk.aio.background.BackgroundUdfFunctionBuilder[source]¶
Bases:
objectPick module and function for a dataset background UDF.
- function(package_name, function_name)[source]¶
Select the registered package and Lua entrypoint.
- Parameters:
- Return type:
- Returns:
BackgroundUdfBuilderfor arguments and execution.- Raises:
ValueError – If either string is empty.
- class aerospike_sdk.aio.background.BackgroundUdfBuilder[source]¶
Bases:
objectArguments, optional filter, and execution for
query_execute_udf.- passing(*args)[source]¶
Set Lua arguments after the implicit record parameter.
- Return type:
- Returns:
This builder for chaining.
- Example::
builder.passing(“arg1”, 42)
- where(expression)[source]¶
- Overloads:
self, expression (str) → BackgroundUdfBuilder
self, expression (FilterExpression) → BackgroundUdfBuilder
Optional predicate limiting which records invoke the UDF.
- records_per_second(rps)[source]¶
Throttle hint stored for API parity (may not affect PAC).
- Return type:
- async execute()[source]¶
Start the background UDF job.
- Raises:
RuntimeError – If the client is not connected.
AerospikeError – On PAC errors (converted).
Example:
task = await ( session.background_task() .execute_udf(users) .function("mypkg", "expire_old") .passing(30) .execute() ) await task.wait_till_complete()
- Return type:
ExecuteTask