xia_meta_task.task.Task
- class xia_meta_task.task.Task(**kwargs)
Bases:
BaseTaskTask is used to help worker to do the stuff
Check concurrency of jobs
Decorate the job call
Trace all
- __init__(**kwargs)
Methods
__init__(**kwargs)append_log(log)delete([caller_id])Delete a document
Delete every instance of this document type
from_db(**kwargs)Transform database data to internal data
Get collection name of current class
get_display_data([lazy])Get Display data (visualized form of data)
get_id()Get document id
Get Raw data (materialized form of data)
Get reverse_delete_rules
inform_busy(owner_name, worker_type, worker_name)Keep a busy cache
is_available([concurrency])is_still_running()list(owner_name[, limit])List objects of predefined criteria, default limited to 10 objects
load(*args, **kwargs)Load a Document from engine
new_rest_task(worker, method[, payload])Generate a new task during rest api call.
objects(**kwargs)Search documents
register_delete_rules(klass, field_path, ...)Use the delete_rule to handle what should happen if the document the field is referencing is deleted.
register_logger()reload()Reload the document from the engine
save([validate])Save a document to engine
save_error(e)Save for successful tasks
Save for successful tasks
Call tasks in synchronous mode
to_db()Translate the runtime data into raw data (materialized form of data)
unregister_logger()update([validate])Update existed fields
validate()Validate if all of the component of document follows the predefined rules
Attributes
BUSY_INTERVALDELETEDENYERRORINFNULLIFYPULLReversed delete rule constant definition
RUNNINGSUCCESSFULTIMEOUTWARNINGaction_nameAction name
busy_workerscaller_idUpstream Task
Cluster Fields
end_timeEnd time of a task
error_messageError Message
error_traceFull python error Trace
Key Fields
loggerlogsLogged information
If the document is not abstract, the collection_name should be provided
nameself_id and No need to check uniqueness for an uuid field
owner_namePartition information
payloadPayload of method call
request_timeWhen the task is requested
reverse_delete_rulesstart_timeStart time of a task
statusCurrent task status
timeoutTask exceed this time will be considered as timeout
transaction_idTransaction ID to trace a whole transaction chain
user_nameHuman who requested this call
worker_nameWorker name
worker_typeWorker type
- REVERSE_DELETE_RULES = {'DELETE': 3, 'DENY': 2, 'NULLIFY': 1, 'PULL': 4}
Reversed delete rule constant definition
- cluster_fields = []
Cluster Fields
- delete(caller_id: Optional[str] = None)
Delete a document
- Parameters
caller_id (str) – The caller of cascade delete
- classmethod delete_all()
Delete every instance of this document type
- engine
alias of
FirestoreEngine
- classmethod from_db(**kwargs)
Transform database data to internal data
- Returns
python dict object
- classmethod get_collection_name()
Get collection name of current class
- Returns
collection name
- Return type
str
- get_display_data(lazy: bool = True)
Get Display data (visualized form of data)
- Returns
python dict object
- get_id()
Get document id
- Returns
Document ID
- Return type
str
- get_raw_data()
Get Raw data (materialized form of data)
- Returns
python dict object
- classmethod get_reverse_delete_rules()
Get reverse_delete_rules
- Returns
reverse delete rules
- Return type
dict
- inform_busy(owner_name: str, worker_type: str, worker_name: str, busy_period: Optional[int] = None)
Keep a busy cache
- Parameters
owner_name – Owner name
worker_type – Worker Type
worker_name – Worker Name
busy_period – Worker is still busy for how much time
- key_fields = []
Key Fields
- classmethod list(owner_name: str, limit: int = 10, **kwargs)
List objects of predefined criteria, default limited to 10 objects
- classmethod load(*args, **kwargs)
Load a Document from engine
- Parameters
*args – a list document id (should only have one valid)
**kwargs –
- Returns
loaded document instance
- meta = {'abstract': True}
If the document is not abstract, the collection_name should be provided
- classmethod new_rest_task(worker: VirtualWorker, method: str, payload: Optional[dict] = None)
Generate a new task during rest api call. Some important parameters are store in g object of Flask
- Parameters
worker – Worker object
method – method to be called
payload – payload to be played
- classmethod objects(**kwargs)
Search documents
- Parameters
**kwargs – Search Configuration
- Returns
generator of a found document
Notes
key, str pair: single value search
key, list pair: array_contains_any search
embedded search: a__b means b component of a. a.b means the key’s name is a.b
- operators: key is end with __op__. The following op are supported:
__eq__: Could ignore because it is a by default behavior
__lt__, __le__, __gt__, __ge__, __ne__: as is supposed by the name
__asc__, __desc__: the result will be ordered by the fields
- partition_info = {}
Partition information
- classmethod register_delete_rules(klass, field_path: str, delete_rule: str)
Use the delete_rule to handle what should happen if the document the field is referencing is deleted.
The options are:
NULLIFY - Updates the reference to null.
CASCADE - Deletes the documents associated with the reference.
DENY - Prevent the deletion of the reference object.
PULL - Pull the reference from a list of reference
- reload()
Reload the document from the engine
- Returns
itself with refreshed data
- save(validate=True)
Save a document to engine
- Parameters
validate (bool) – Should the validation to be passed or not
- Returns
itself (with document id in the case of a new created document)
- save_error(e: Exception)
Save for successful tasks
- Parameters
e – Exception Objects
Returns:
- save_successful()
Save for successful tasks
Returns:
- sync_call()
Call tasks in synchronous mode
- Returns
Task execution results
- to_db()
Translate the runtime data into raw data (materialized form of data)
- Returns
python dict object
- update(validate=True, **kwargs)
Update existed fields
- Parameters
validate (bool) – Should the data be validated before update or not
**kwargs – update parameters
- Returns
updated document in the form of python dict
Notes
Update String Specifications * embedded update: a__b means b component of a. a.b means the key’s name is a.b * operators: key is end with __op__. The following op are supported:
__append__: Append an item to array
__remove__: Remove an item
__delete__: Delete the field
Notes
We need to update the data from all sources
- validate()
Validate if all of the component of document follows the predefined rules
- Returns
Always None. No exception raised means the validation passed