Module for handling possibly long running tasks
- Description:
Module for handling possibly long running tasks
- Source:
Methods
(static) checkIfRunning(options, callback)
- Description:
Check if task like that is arleady running or not
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||||||||||||||||||
callback |
funciton | callback for the result |
(static) checkResult(options, callback)
- Description:
Check task's status
- Source:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||
callback |
funciton | callback for the result |
(static) createTask(options, callbackopt)
- Description:
Create task with data, without result
- Source:
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
callback |
function |
<optional> |
callback when data is stored |
(static) deleteAdditionalResults(task, options, callback)
- Description:
Delete additional results specific to task type
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
task |
object | the task object |
options |
object | options for the task |
callback |
function | callback for the result |
(static) deleteResult(options, callback)
- Description:
Delete specific task result
- Source:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||
callback |
funciton | callback for the result |
(static) editTask(options, callback)
- Description:
Edit specific task
- Source:
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||
callback |
funciton | callback for the result |
(static) errorResults(options, callback)
- Description:
Mark all running or rerunning tasks as errored
- Source:
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||
callback |
funciton | callback for the result |
(static) getCounts(options, callback)
- Description:
Get task counts based on query and grouped by app_id
- Source:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||
callback |
funciton | callback for the result |
(static) getId() → {string}
- Description:
Generates ID for the task
- Source:
Returns:
id to be used when saving the task
- Type
- string
(static) getResult(options, callback)
- Description:
Get specific task result
- Source:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||
callback |
funciton | callback for the result |
(static) getResultByQuery(options, callback)
- Description:
Get specific task result
- Source:
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||
callback |
funciton | callback for the result |
(static) getResults(options, callback)
- Description:
Get multiple task results based on query
- Source:
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||
callback |
funciton | callback for the result |
(static) getTableQueryResult(options, callback)
- Description:
Get dataTable query results for tasks
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||||||||
callback |
funciton | callback for the result |
(static) isAuthorizedFor(member, task) → {boolean}
- Description:
Authorize a member to act on a long_tasks document.
A task is operatable only by:
- global admins,
- the member who created it (task.creator === member._id),
- app-admins of the task's app_id (when task.app_id is set).
The /i/tasks/{update,delete,name,edit} endpoints used to be reachable by any logged-in user (validateUserForWrite is just validateUser), which made it possible to rerun, rename, edit, or delete tasks belonging to other users / apps. rerunTask in particular replays the original request using the creator's api_key, which is a cross-tenant privilege escalation.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
member |
object | params.member from request context |
task |
object | long_tasks document |
Returns:
true if the member is allowed to operate on this task
- Type
- boolean
(static) loadIfAuthorized(db, id, member, cb)
- Description:
Load a task by id, then call cb(err, task) only if
memberis authorized for it. If unauthorized, cb is called with err === 'forbidden'.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
db |
object | database connection |
id |
string | task id |
member |
object | params.member |
cb |
function | cb(err, task) |
(static) longtask(options) → {function}
- Description:
Monitors DB query or some other potentially long task and switches to long task manager if it exceeds threshold
- Source:
Example
common.db.collection("data").findOne({_id:"test"}, taskmanager.longtask({
db:common.db,
threshold:30,
force:false,
app_id:"58b6d13bf1de9562e5a8029f",
params: params,
type:"funnels",
meta: {},
name:"FunnelName",
view:"#/funnels/task/",
processData:function(err, res, callback){
if(!err)
callback(null, res);
else
callback(null, {});
}, outputData:function(err, data){
common.returnOutput(params, data);
}
}));
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
Returns:
standard nodejs callback function accepting error as first parameter and result as second one. This result is passed to processData function, if such is available.
- Type
- function
(static) nameResult(options, data, callbackopt)
- Description:
Give a name to task result or rename it
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||||||
data |
object | not used at all. pass anything. left for compability |
|||||||||||||
callback |
function |
<optional> |
callback when data is stored |
(static) rerunTask(options, callback)
- Description:
Rerun specific task
- Source:
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
|||||||||||||||
callback |
funciton | callback for the result |
(static) saveResult(options, data, callbackopt)
- Description:
Save result from the task
- Source:
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | options for the task Properties
|
||||||||||||||||||||||
data |
object | result data of the task |
||||||||||||||||||||||
options.gridfs |
boolean | store result in gridfs instead of MongoDB document |
||||||||||||||||||||||
callback |
function |
<optional> |
callback when data is stored |
(inner) getResult(callback, options) → {function}
- Description:
Create a callback for getting result, including checking gridfs
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function | callback for the result |
options |
object | options object |
Returns:
callback to use for db query
- Type
- function