core.tasks
¶
Module Contents¶
Classes¶
Base class for user-callable tasks. |
|
Task Handler. |
|
This is the meta class for QueryIters. |
|
BaseClass to run a database Query and process each entry matched. |
|
Simple Query-Iter to delete all entities encountered. |
Functions¶
Add support for Keys, Datetime, Bytes and db.Entities in deferred tasks. |
|
|
Inverse to JsonKeyEncoder: Check if the object matches a custom ViUR type and recreate it accordingly |
|
Removes a periodic task from the queue. Useful to unqueue an task |
|
Prevents a deferred Function from being called a second time |
|
This is a decorator, which always calls the function deferred. |
|
Deprecated version of CallDeferred |
|
Decorator to call a function periodic during maintenance. |
|
Marks a Class as representing a user-callable Task. |
|
Functions decorated with this are called shortly at instance startup. |
Runs all queued startupTasks. |
Attributes¶
- core.tasks.preprocessJsonObject(o)¶
Add support for Keys, Datetime, Bytes and db.Entities in deferred tasks. This is not a subclass of json.JSONEncoder anymore, as db.Entites are a subclass of dict, which is always handled from the json module itself.
- core.tasks.jsonDecodeObjectHook(obj)¶
Inverse to JsonKeyEncoder: Check if the object matches a custom ViUR type and recreate it accordingly
- core.tasks._gaeApp¶
- core.tasks.queueRegion¶
- core.tasks.headers¶
- core.tasks.taskClient¶
- core.tasks._periodicTasks :Dict[str, Dict[Callable, int]]¶
- core.tasks._callableTasks¶
- core.tasks._deferred_tasks¶
- core.tasks._startupTasks = []¶
- core.tasks._appengineServiceIPs¶
- exception core.tasks.PermanentTaskFailure¶
Bases:
Exception
Indicates that a task failed, and will never succeed.
- core.tasks.removePeriodicTask(task: Callable) None ¶
Removes a periodic task from the queue. Useful to unqueue an task that has been inherited from an overridden module.
- class core.tasks.CallableTaskBase¶
Base class for user-callable tasks. Must be subclassed.
- key¶
- name¶
- descr¶
- kindName = server-task¶
- canCall() bool ¶
Checks wherever the current user can execute this task :returns: bool
- dataSkel()¶
If additional data is needed, return a skeleton-instance here. These values are then passed to execute.
- execute()¶
The actual code that should be run goes here.
- class core.tasks.TaskHandler(moduleName, modulePath)¶
Task Handler. Handles calling of Tasks (queued and periodic), and performs updatececks Do not Modify. Do not Subclass.
- adminInfo¶
- retryCountWarningThreshold = 25¶
- exposed = True¶
- exposed = True¶
- exposed = True¶
- exposed = True¶
- exposed = True¶
- findBoundTask(task: Callable, obj: object = None, depth: int = 0) Tuple[Callable, object] | None ¶
Tries to locate the instance, this function belongs to. If it succeeds in finding it, it returns the function and its instance (-> its “self”). Otherwise, None is returned. :param task: A callable decorated with @PeriodicTask :param obj: Object, which will be scanned in the current iteration. None means start at conf[“viur.mainApp”]. :param depth: Current iteration depth.
- queryIter(*args, **kwargs)¶
This processes one chunk of a queryIter (see below).
- deferred(*args, **kwargs)¶
This catches one deferred call and routes it to its destination
- cron(cronName='default', *args, **kwargs)¶
- list(*args, **kwargs)¶
Lists all user-callable tasks which are callable by this user
- execute(taskID, *args, **kwargs)¶
Queues a specific task for the next maintenance run
- core.tasks.admin = True¶
- core.tasks.vi = True¶
- core.tasks.html = True¶
- core.tasks.noRetry(f)¶
Prevents a deferred Function from being called a second time
- core.tasks.CallDeferred(func)¶
This is a decorator, which always calls the function deferred. Unlike Googles implementation, this one works (with bound functions)
- core.tasks.callDeferred(func)¶
Deprecated version of CallDeferred
- core.tasks.PeriodicTask(interval: int = 0, cronName: str = 'default') Callable ¶
Decorator to call a function periodic during maintenance. Interval defines a lower bound for the call-frequency for this task; it will not be called faster than each interval minutes. (Note that the actual delay between two sequent might be much larger)
- Parameters:
interval – Call at most every interval minutes. 0 means call as often as possible.
- core.tasks.CallableTask(fn: Callable) Callable ¶
Marks a Class as representing a user-callable Task. It should extend CallableTaskBase and must provide its API
- core.tasks.StartupTask(fn: Callable) Callable ¶
Functions decorated with this are called shortly at instance startup. It’s not guaranteed that they actually run on the instance that just started up! Wrapped functions must not take any arguments.
- core.tasks.runStartupTasks()¶
Runs all queued startupTasks. Do not call directly!
- class core.tasks.MetaQueryIter(name, bases, dct)¶
Bases:
type
This is the meta class for QueryIters. Used only to keep track of all subclasses of QueryIter so we can emit the callbacks on the correct class.
- _classCache¶
- class core.tasks.QueryIter¶
Bases:
object
BaseClass to run a database Query and process each entry matched. This will run each step deferred, so it is possible to process an arbitrary number of entries without being limited by time or memory.
To use this class create a subclass, override the classmethods handleEntry and handleFinish and then call startIterOnQuery with an instance of a database Query (and possible some custom data to pass along)
- queueName = default¶
- classmethod startIterOnQuery(query: viur.core.db.Query, customData: Any = None) None ¶
Starts iterating the given query on this class. Will return immediately, the first batch will already run deferred.
Warning: Any custom data must be json-serializable and must be passed in customData. You cannot store any data on this class as each chunk may run on a different instance!
- classmethod _requeueStep(qryDict: Dict[str, Any]) None ¶
Internal use only. Pushes a new step defined in qryDict to either the taskqueue or append it to the current request if we are on the local development server.
- classmethod _qryStep(qryDict: Dict[str, Any]) None ¶
Internal use only. Processes one block of five entries from the query defined in qryDict and reschedules the next block.
- classmethod handleEntry(entry, customData)¶
Overridable hook to process one entry. “entry” will be either an db.Entity or an SkeletonInstance (if that query has been created by skel.all())
Warning: If your query has an sortOrder other than __key__ and you modify that property here it is possible to encounter that object later one again (as it may jump behind the current cursor).
- classmethod handleFinish(totalCount: int, customData)¶
Overridable hook that indicates the current run has been finished.
- classmethod handleError(entry, customData, exception) bool ¶
Handle a error occurred in handleEntry. If this function returns True, the queryIter continues, otherwise it breaks and prints the current cursor.
- class core.tasks.DeleteEntitiesIter¶
Bases:
QueryIter
Simple Query-Iter to delete all entities encountered.
- ..Warning: Do not use this iter on skeletons. It only works on the low-level db API and would not clear
relations, locks etc.
- classmethod handleEntry(entry, customData)¶
Overridable hook to process one entry. “entry” will be either an db.Entity or an SkeletonInstance (if that query has been created by skel.all())
Warning: If your query has an sortOrder other than __key__ and you modify that property here it is possible to encounter that object later one again (as it may jump behind the current cursor).