15.2.160. camcops_server.cc_modules.cc_taskcollection

camcops_server/cc_modules/cc_taskcollection.py


Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.


Classes to fetch tasks from the database as efficiently as possible.

class camcops_server.cc_modules.cc_taskcollection.FetchThread(req: CamcopsRequest, task_class: Type[camcops_server.cc_modules.cc_task.Task], factory: TaskCollection, **kwargs)[source]

Thread to fetch tasks in parallel.

CURRENTLY UNUSED.

__init__(req: CamcopsRequest, task_class: Type[camcops_server.cc_modules.cc_task.Task], factory: TaskCollection, **kwargs) None[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run() None[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class camcops_server.cc_modules.cc_taskcollection.TaskCollection(req: Optional[CamcopsRequest], taskfilter: camcops_server.cc_modules.cc_taskfilter.TaskFilter = None, as_dump: bool = False, sort_method_by_class: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = TaskSortMethod.NONE, sort_method_global: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = TaskSortMethod.NONE, current_only: bool = True, via_index: bool = True, export_recipient: ExportRecipient = None)[source]

Represent a potential or instantiated call to fetch tasks from the database.

The caller may want them in a giant list (e.g. task viewer, CTVs), or split by task class (e.g. trackers).

__init__(req: Optional[CamcopsRequest], taskfilter: camcops_server.cc_modules.cc_taskfilter.TaskFilter = None, as_dump: bool = False, sort_method_by_class: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = TaskSortMethod.NONE, sort_method_global: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = TaskSortMethod.NONE, current_only: bool = True, via_index: bool = True, export_recipient: ExportRecipient = None) None[source]
Parameters
property all_tasks: List[camcops_server.cc_modules.cc_task.Task]

Returns a list of all appropriate task instances.

property all_tasks_or_indexes_or_query: Union[List[camcops_server.cc_modules.cc_task.Task], List[camcops_server.cc_modules.cc_taskindex.TaskIndexEntry], sqlalchemy.orm.query.Query]

Returns a list of all appropriate task instances, or index entries, or a query returning them.

  • Returning a list of tasks is fine, but the results of this function may be paginated (e.g. in the main task view), so the end result may be that e.g. 20,000 tasks are fetched and 20 are shown.

  • More efficient is to fetch 20,000 indexes from the single index table, and fetch only the 20 tasks we need.

  • More efficient still is to fetch the 20 indexes we need, and then their task.

property dbsession: sqlalchemy.orm.session.Session

Returns the request’s database session.

gen_all_tasks_or_indexes() Generator[Union[camcops_server.cc_modules.cc_task.Task, camcops_server.cc_modules.cc_taskindex.TaskIndexEntry], None, None][source]

Generates tasks or index entries.

gen_tasks_by_class() Generator[camcops_server.cc_modules.cc_task.Task, None, None][source]

Generates all tasks, class-wise.

gen_tasks_in_global_order() Generator[camcops_server.cc_modules.cc_task.Task, None, None][source]

Generates all tasks, in the global order.

property req: CamcopsRequest

Returns the associated request, or raises AssertionError if it’s not been set.

set_request(req: CamcopsRequest) None[source]

Sets the request object manually. Used by Celery back-end tasks.

Parameters

req – a camcops_server.cc_modules.cc_request.CamcopsRequest

task_classes() List[Type[camcops_server.cc_modules.cc_task.Task]][source]

Return a list of task classes that we want.

tasks_for_task_class(task_class: Type[camcops_server.cc_modules.cc_task.Task]) List[camcops_server.cc_modules.cc_task.Task][source]

Returns all appropriate task instances for a specific task type.

class camcops_server.cc_modules.cc_taskcollection.TaskSortMethod(value)[source]

Enum representing ways to sort tasks.

camcops_server.cc_modules.cc_taskcollection.decode_task_collection(d: Dict, cls: Type) camcops_server.cc_modules.cc_taskcollection.TaskCollection[source]

Creates a TaskCollection from a serialized version.

The request is not serialized and must be rebuilt in another way; see e.g. camcops_server.cc_modules.celery.email_basic_dump().

camcops_server.cc_modules.cc_taskcollection.encode_task_collection(coll: camcops_server.cc_modules.cc_taskcollection.TaskCollection) Dict[source]

Serializes a TaskCollection.

The request is not serialized and must be rebuilt in another way; see e.g. camcops_server.cc_modules.celery.email_basic_dump().

camcops_server.cc_modules.cc_taskcollection.reorder_args(content_type: str, content_encoding: str, data: str) List[str][source]

kombu SerializerRegistry.dumps() returns data as last element in tuple but for SerializeRegistry.loads() it’s the first argument

camcops_server.cc_modules.cc_taskcollection.sort_tasks_in_place(tasklist: List[camcops_server.cc_modules.cc_task.Task], sortmethod: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod) None[source]

Sort a list of tasks, in place, according to sortmethod.

Parameters
camcops_server.cc_modules.cc_taskcollection.task_when_created_sorter(task: camcops_server.cc_modules.cc_task.Task) Union[Tuple[pendulum.datetime.DateTime, datetime.datetime], cardinal_pythonlib.sort.MinType][source]

Function to sort tasks by their creation date/time (with upload date/time as a tiebreak for consistent ordering).