Collection of Utility functions
Methods
(static) computeHash(algorithm, value) → {String}
Compute a digest using the specified algorithm on the specified Buffer value.
Parameters:
Name | Type | Description |
---|---|---|
algorithm |
String | |
value |
Buffer |
Returns:
- a hex string representing the output digest
- Type
- String
(static) copyFile(srcPath, destPathopt)
Copies a file into the log directory
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
srcPath |
String | Absolute path to a source file. |
|
destPath |
String |
<optional> |
Destination path relative to the log root directory. The filename from the source file will be used if unspecified. |
(static) createFile(filename, data)
Creates a new file.
Parameters:
Name | Type | Description |
---|---|---|
filename |
String | Filename. This is relative path to log directory. |
data |
String | Buffer | String data to be written to a file. |
(static) createSyncSandbox(func, options)
Creates SyncSandbox for using utility.sync utility.sync requires SyncSandbox
Example
utility.createSyncSandbox(() => { utility.sync('wait', () => {}) })
utility.createSyncSandbox(() => { utility.sync('wait 1', () => {}) }, { timeout: 600 })
// It will wait maximum 600 seconds until all ports join SyncSandbox.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
func |
function | this function will be executed in a sandbox |
|||||||||||||||
options |
Object |
Properties
|
(static) deleteFile(filename)
Deletes a file.
Parameters:
Name | Type | Description |
---|---|---|
filename |
String | Filename. This is relative path to log directory. |
(static) exec(command, optionsopt)
Creates a then executes the command within that shell.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
command |
String | ||||||||||||||
options |
Object |
<optional> |
Properties
|
(static) fetchUrl(url, optionsopt) → {HttpResponse}
Makes a request to fetch a URL.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
String | The URL to fetch. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
The optional JavaScript object specifying advanced parameters. Properties
|
Returns:
- Type
- HttpResponse
(static) getTaskInfo() → {utility.TaskInfo}
Returns the current task info.
Example
const taskInfo = utility.getTaskInfo()
Returns:
- Type
- utility.TaskInfo
(static) readFile(filepath, optionsopt) → {Buffer}
Read a file.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filepath |
String | File path.
|
|||||||||||
options |
Object |
<optional> |
Properties
|
Returns:
file data
- Type
- Buffer
(static) setOutputContext(context)
Sets an output context that is visible from the coordinator.
Example
utility.setOutputContext({hello:"world"})
// outputContext is visible from the coordinator when set.
const outputContext = utility.getTaskInfo().outputContext
Parameters:
Name | Type | Description |
---|---|---|
context |
Object |
(static) sleep(ms)
Adds delay in milliseconds.
Parameters:
Name | Type | Description |
---|---|---|
ms |
Number | Delay in milliseconds. |
(static) sync(syncPoint, func, options)
Synchronizes all ports
Example
utility.createSyncSandbox(() => { aFunction(); utility.sync('point1', () => {}); bFunction() })
// Each port waits at "point1" until all ports reaches at "point1".
utility.createSyncSandbox(() => { utility.sync('point2', aFunction, { exclusiveCount = 1 }); bFunction() })
// Only one port can run the function "aFunction".
// Other ports will wait at "point2" until all ports reaches at "point2".
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
syncPoint |
String | synchronization point name |
|||||||||||||||
func |
function | this function will be executed in the sync |
|||||||||||||||
options |
Object |
Properties
|
(static) systemInfo() → {utility.SystemInfo}
Returns system information.
Returns:
- Type
- utility.SystemInfo
(static) writeFile(filename, data)
Writes strings to a file.
Parameters:
Name | Type | Description |
---|---|---|
filename |
String | Filename. This is relative path to log directory. |
data |
String | Buffer | String data to be written to a file. |
Type Definitions
SystemInfo
Properties:
Name | Type | Description |
---|---|---|
cpus |
Array.<Object> | List of CPUs. |
hostname |
String | Hostname. |
platform |
String | OS platform. |
type |
String | OS type. |
totalmem |
Number | Total installed memory. |
uptime |
Number | Uptime since power on. |
port |
Number | IO Buster port number. |
totalPorts |
Number | Total number of IO Buster ports. |
version |
String | IO Buster version. |
buildVersion |
String | IO Buster build commit hash. |
Type:
- Object
TaskInfo
Properties:
Name | Type | Description |
---|---|---|
taskId |
String | Current Task ID. |
entryScript |
String | The entry script for this task. |
startTime |
Number | The task start time in UTC. |
inputContext |
Object | The inputs received when starting a task. |
outputContext |
Object | The outputs set by |
Type:
- Object