tasks — Task registry backed by SQLite (via sigma/sqlite JDBC wrapper).
Overview
A persistent task registry to schedule and track execution of automation scripts across devices.
- Main table: tasks (one row per task)
- Child table: task_paths (one task → many paths)
- Devices master: task_devices (deduplicated by
(device_name, device_sn)) - Relation table: task_path_devices (many-to-many between paths and devices)
The public API returns camelCase fields and keeps backward-friendly names where required。
Key Features
- Connection & Pragmas: WAL, NORMAL sync, busy timeout.
- Create:
tasksCreate()supports both the simple signature and a full object withoptions. - Update:
tasksUpdate()handles camelCase → snake_case mapping for main task fields and
recomputesplan_timewhenrepeat/timeis changed. - Delete:
tasksDelete()&tasksDeleteMany()with cascade cleanup via FKs. - Query:
tasksList()/tasksGet()aggregate paths and devices intooptionsfor output. - Search/Count: LIKE-based search across key fields; status grouping.
- Controls:
tasksPause()/tasksResume()/tasksStop()delegate to the underlying executor.
Status Values (negative convention kept)
0 : FILE_NOT_FOUND — Script path does not exist (pre-run validation failure)
-1 : RUNNING
-2 : STOPPED_NORMAL
-3 : STOPPED_ERROR
-4 : PAUSED
-5 : USER_TERMINATED
-6 : SCHEDULED (default upon creation)
Storage — Tables
tasks (main)
id INTEGER PK AUTOINCREMENTauto_connect INTEGER NOT NULL DEFAULT 0auto_select INTEGER NOT NULL DEFAULT 0start_time INTEGER NOT NULL// ms epochend_time INTEGER// ms epocherror_message TEXT NOT NULL DEFAULT ''exec_count INTEGER NOT NULL DEFAULT 1exec_device TEXT NOT NULL DEFAULT '-'expiration INTEGER NOT NULL DEFAULT 0iter_count INTEGER NOT NULL DEFAULT 1plan_time INTEGER// ms epoch; computed fromtime/repeatre_exec INTEGER NOT NULL DEFAULT 0status INTEGER NOT NULL DEFAULT -6task_id INTEGER NOT NULL UNIQUE// business-visible idtask_name TEXT NOT NULL UNIQUEweek_json TEXT// optional serialized repeat weekdays ["0".."6"]created_at INTEGER NOT NULL// ms epochupdated_at INTEGER NOT NULL// ms epochtimezone TEXT NOT NULL// e.g. "Asia/Shanghai"sigma_test_status TEXT DEFAULT NULL// e.g. "{T:320,P:280,F:30,E:10}"
Indexes: by status, plan_time, updated_at, and LIKE on task_name.
task_paths
id INTEGER PK AUTOINCREMENTtask_row_id INTEGER NOT NULL// FK → tasks.id (row id)path TEXT NOT NULLcreated_at INTEGER NOT NULL// ms epochupdated_at INTEGER NOT NULL// ms epoch
task_devices (master)
id INTEGER PK AUTOINCREMENTdevice_name TEXT NOT NULLdevice_sn TEXT NOT NULLcreated_at INTEGER NOT NULL// ms epochupdated_at INTEGER NOT NULL// ms epochUNIQUE(device_name, device_sn)
task_path_devices (relation)
(task_path_id INTEGER, task_device_id INTEGER)as composite PKcreated_at INTEGER NOT NULL// ms epoch- FKs cascade on delete of path/device
Returned Shapes
Both tasksList() and tasksGet() return objects in this format (example array with one item):
[{
"autoConnect": false,
"autoSelect": false,
"startTime": 1757922442739,
"endTime": 1757922442782,
"errorMessage": "",
"execCount": 1,
"execDevice": "-",
"expiration": 0,
"iterCount": 1,
"reExec": false,
"options": [
{ "device_names": [], "device_sn": [], "path": "C:/.../1.js" }
],
"status": -2,
"taskID": 1759213730566,
"taskName": "1111(3)",
"createdAt": 1757922442739,
"updatedAt": 1757922442739,
"timezone": "Asia/Shanghai",
"sigma_test_status": "{T:320,P:280,F:30,E:10}"
}]
Notes:
createdAt/updatedAtare long (ms epoch), not ISO strings.
Simple Overload Enhancements
- Adds support for
tasksCreate(name, scriptFile, options)signature. - The
optionsobject may include:iteration: number— number of executions.time: string— "YYYY-MM-DD HH:mm[:ss]" (one-shot) or "HH:mm[:ss]" (repeat).repeat: number[]— weekdays [0..6]; e.g., [1,3,5] for Mon/Wed/Fri.deviceName: string|string[]— single device (also accepts one-element array).deviceNames: string[]— multiple devices.deviceSN: string|string[]anddeviceSNs: string[]— optional serial numbers.
- When the counts of
deviceName(s)anddeviceSN(s)differ, the shorter array is automatically padded with empty strings"". - All inserts (
tasks,task_paths, andtask_path_devices) occur within the same transaction. - Backward compatible with
(name, scriptFile, iteration?, time?, repeat?).
Example Usage
var tasks = require("sigma/tasks");
// Simple creation (single path, no devices):
tasks.tasksCreate("nightly", "C:/Scripts/a.js", 1, "2025-12-01 08:00");
// Listing (aggregates options from normalized tables):
var list = tasks.tasksList({ status: tasks.STATUS.SCHEDULED, limit: 20 });
print(JSON.stringify(list, null, 2));
// Simplified object overload
tasksCreate("task001", "F:/test/test.js", { iteration: 2 });
tasksCreate("task002", "F:/test/test.js", { iteration: 1, time: "2020-06-30 14:30" });
tasksCreate("task003", "F:/test/test.js", { iteration: 1, time: "14:30", repeat: [3,5] });
// Single device
tasksCreate("task004", "F:/File/text.js", { iteration: 1, time: "14:30", repeat: [3,5], deviceName: ["PIONEER K88L"] });
// Multiple devices
tasksCreate("task005", "E:/File/test.js", { iteration: 1, time: "2020-07-30 15:30", deviceNames: ["PIONEER K88L","PIONEER K88L1"] });
// If deviceNames and deviceSNs differ in length, the shorter is automatically padded with ""
Design Notes
- All timestamps use ms epoch. Timezone is captured per task at creation/update.
- Devices are deduplicated globally; many-to-many relation binds devices to per-path rows.
- CRUD on tasks cascades to paths and relations via FKs. Device master rows are retained
unless you explicitly garbage-collect unreferenced devices.
Functions
Members
(inner, constant) DEFAULT_DB_URL
Default SQLite database location:
Uses: global.getAppData() + "/Scripts/tasks.db"
(Future: may support JVM system property TASKS_DB or process.env.TASKS_DB.)
(inner) hasJsExt(p) → {boolean}
Check whether a given path has a recognized JavaScript-like extension.
Supports .js, .tst, and .scp file types.
Example
hasJsExt("main.js"); // → true
hasJsExt("unit.tst"); // → true
hasJsExt("macro.scp"); // → true
hasJsExt("readme.txt"); // → false
Parameters:
| string | p |
The file path or name to check. |
Returns:
| boolean |
True if it ends with |
| number | fromStatus |
Only tasks currently with this status will be updated. |
|||||||||||||||||
| number | toStatus |
The new status value to set. |
|||||||||||||||||
| Object | opts |
<optional> |
Optional filter options. Properties
|
Returns:
| Object | false |
Returns statistics about the operation. |
| object | filters |
<optional> |
Properties
|
Returns:
| object |
|
| string | name |
Unique task name (non-empty). |
||
| string | scriptFile |
Absolute path to a |
||
| number | iteration |
<optional> |
1 | Number of planned executions (>=1). |
| string | time |
<optional> |
Repeat: |
|
| Array.<(number|string)> | repeat |
<optional> |
Weekdays |
Returns:
| boolean | null |
|
| Array | items |
||
| boolean | opts |
<optional> |
Returns:
| object |
|
| number | string | idOrName |
Returns:
| boolean |
true if one or more rows were deleted; false otherwise. and the specific error message is obtained by the lastError() function. |
| Array.<(number|string)> | idsOrNames |
||
| Object | opts |
<optional> |
Returns:
| Object |
| string | name |
Task name |
Returns:
| boolean |
true if exists, false otherwise |
| number | string | idOrName |
Returns:
| Object | null |
Aggregated task or null if not found |
| object | filters |
<optional> |
Properties
|
Returns:
| Array.<Object> |
Aggregated tasks |
| String | name |
The name of the tasks |
Returns:
| boolean | null |
Returns true if successful, false if it fails, and the specific error message is obtained by the lastError() function. |
| boolean | confirm |
Must be |
Throws:
| Error |
If |
| String | name |
The name of the tasks. |
Returns:
| boolean | null |
Returns true if successful, false if it fails, and the specific error message is obtained by the lastError() function. |
| string | query |
Non-empty search string (raw; escaping handled internally) |
|||||||||||||||||||||||||||||||
| object | opts |
<optional> |
Properties
|
Returns:
| Array.<Object> |
Aggregated tasks |
| String | name |
The name of the tasks. |
Returns:
| boolean | null |
Returns true if successful, false if it fails, and the specific error message is obtained by the lastError() function. |
| number | string | idOrName |
|
| object | patch |
Allowed keys:
|
Returns:
| boolean | null |
|