api/utils/taskmanager

Module for handling possibly long running tasks

Source:

Methods

(static) checkIfRunning(options, callback)

Source:

Check if task like that is arleady running or not

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Attributes Description
db object

database connection

id string <optional>

id of the task result

type string <optional>

type of data, as which module or plugin uses this data

meta string <optional>

any information about the taskManager

params params <optional>

params object

request object <optional>

api request to be able to rerun this task

callback funciton

callback for the result

(static) checkResult(options, callback)

Source:

Check task's status

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id of the task result

callback funciton

callback for the result

(static) createTask(options, callbackopt)

Source:

Create task with data, without result

Parameters:
Name Type Attributes Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id to use for this task

type string

type of data, as which module or plugin uses this data

meta string

any information about the taskManager

name string

provide user friendly task running condition string(Like, "Session (sc > 1024)" shows the report will filter by session count bigger than 1024)

report_name string

name inputed by user create from report form

report_desc string

report desc from report form

period_desc string

target period report data from report form

view string

browser side view hash prepended with job id to display result

request object

api request to be able to rerun this task

app_id string

id of the app for which data is for

start number

start time of the task in miliseconds (by default now)

creator string

the task creator

global string

the task is private or global visit.

autoRefresh boolean

the task is will auto run periodically or not.

r_hour number

the task local hour of time to run, when autoRefresh is true.

manually_create boolean

the task is create from form input

callback function <optional>

callback when data is stored

(static) deleteResult(options, callback)

Source:

Delete specific task result

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id of the task result

callback funciton

callback for the result

(static) editTask(options, callback)

Source:

Edit specific task

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id object

ID of the target task

data string

data of the task want to modify

callback funciton

callback for the result

(static) errorResults(options, callback)

Source:

Mark all running or rerunning tasks as errored

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

callback funciton

callback for the result

(static) getCounts(options, callback)

Source:

Get task counts based on query and grouped by app_id

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

query object

mongodb query

callback funciton

callback for the result

(static) getId() → {string}

Source:

Generates ID for the task

Returns:

id to be used when saving the task

Type
string

(static) getResult(options, callback)

Source:

Get specific task result

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id of the task result

callback funciton

callback for the result

(static) getResultByQuery(options, callback)

Source:

Get specific task result

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

query string

query for the task result

callback funciton

callback for the result

(static) getResults(options, callback)

Source:

Get multiple task results based on query

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

query object

mongodb query

projection object

mongodb projection

callback funciton

callback for the result

(static) getTableQueryResult(options, callback)

Source:

Get dataTable query results for tasks

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

query object

mongodb query

projection object

mongodb projection

page object

mongodb offset & limit

keyword object

search task "report_name" or "report_desc"

callback funciton

callback for the result

(static) longtask(options) → {function}

Source:

Monitors DB query or some other potentially long task and switches to long task manager if it exceeds threshold

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
Name Type Description
db object

database connection

params params

params object

threshold number

amount of seconds to wait before switching to long running task

force number

force to use taskmanager, ignoring threshold

type string

type of data, as which module or plugin uses this data

meta string

any information about the tast

name string

provide user friendly task running condition string(Like, "Session (sc > 1024)" shows the report will filter by session count bigger than 1024)

report_name string

name inputed by user create from report form

report_desc string

report desc from report form

period_desc string

target period report data from report form

name string

provide user friendly task running condition string

view string

browser side view hash prepended with job id to display result

app_id string

id of the app for which data is meant for

processData function

function to which to feed fetched data to post process it if needed, should accept err, data and callback to which to feed processed data

outputData function

function to which to feed post processed data, if task did not exceed threshold

creator string

the task creator

global boolean

the task is private or global visit.

autoRefresh boolean

the task is will auto run periodically or not.

r_hour number

the task local hour of time to run, when autoRefresh is true.

forceCreateTask boolean

force createTask with id supplied ( for import)

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)

Source:

Give a name to task result or rename it

Parameters:
Name Type Attributes Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id to use for this task

name string

name of the task result, for later reference

data object

not used at all. pass anything. left for compability

callback function <optional>

callback when data is stored

(static) rerunTask(options, callback)

Source:

Rerun specific task

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id of the task result

callback funciton

callback for the result

(static) saveResult(options, data, callbackopt)

Source:

Save result from the task

Parameters:
Name Type Attributes Description
options object

options for the task

Properties
Name Type Description
db object

database connection

id string

id to use for this task

errored boolean

if errored then true

errormsg object

data object for error msg - can be also error msg (string)

Properties
Name Type Description
message string

Optional. if exists check for message here. If not uses options.errormsg.

data object

result data of the task

callback function <optional>

callback when data is stored

(inner) getResult(callback, options) → {function}

Source:

Create a callback for getting result, including checking gridfs

Parameters:
Name Type Description
callback function

callback for the result

options object

options object

Returns:

callback to use for db query

Type
function