Jobs - egodigital/vscode-powertools GitHub Wiki

Jobs can be used to run tasks, like scripts or shell commands, periodically.

Create a jobs section to the settings.json file in the .vscode sub folder of your workspace and add one or more entry:

{
    "ego.power-tools": {
        "jobs": [
            {
                "name": "My job",
                "description": "A job that runs all 30 seconds.",
                "time": "*/30 * * * * *",
                "action": {
                    "type": "script",
                    "script": "my_job.js"
                }
            }
        ]
    }
}

For that example, create a my_job.js file in your .vscode folder and use the following skeleton:

exports.execute = async (args) => {
    // args => https://egodigital.github.io/vscode-powertools/api/interfaces/_contracts_.jobitemscriptactionarguments.html

    // s. https://code.visualstudio.com/api/references/vscode-api
    const vscode = args.require('vscode');

    vscode.window.showInformationMessage(
        'Hello, it is: ' + (new Date())
    );
};

To start or stop jobs, press F1, select Power Tools: Jobs and choose the one, you would like to change its running state for.

demo-jobs.gif

Settings

Name Description Required?
action The action to invoke. yes
autoStart Run job on startup or not. Default: (true) no
button Settings for an optional button to start or stop the job. no
description1 A description for the job. no
format1 The format of time setting. Current supports: crontab. Default: crontab no
if (JavaScript) Code that checks if job is available or not. s. Conditional Settings no
importValues Defines a list of properties, which uses (external) values for itself. s. Import Settings no
name1 The (display) name of the job. no
onCreated The (JavaScript) code to executed after job has been created. s. Executable Settings no
onDestroyed The (JavaScript) code to executed after job has been destroyed. s. Executable Settings no
platforms A list of one or more platform IDs, where the job should be available on. s. process.platform no
time1 The (crontab) time. Default: 0 * * * * * no

1 supports placeholders

action

Name Description Required?
type The type. Current supports: script and shell. Default: shell no

Scripts

Runs a Node.js based script file.

{
    "ego.power-tools": {
        "jobs": [
            {
                "name": "My job",
                "description": "A job that runs all 30 seconds.",
                "time": "*/30 * * * * *",
                "action": {
                    "type": "script",
                    "script": "my_job.js",
                    "options": "<Any JavaScript object / value can be used>"
                }
            }
        ]
    }
}
Name Description Required?
options Options for the script. no
script1 The path to the script that should be invoked. Relative paths will be mapped to the .vscode sub folder of the workspace or the .vscode-powertools sub folder inside the current user's home directory. yes

1 supports placeholders

Shell commands

Runs a shell command.

{
    "ego.power-tools": {
        "jobs": [
            {
                "name": "My job",
                "description": "A job that runs a 'git fetch' all 30 minutes.",
                "time": "0 */30 * * * *",
                "action": {
                    "type": "shell",
                    "command": "git fetch"
                }
            }
        ]
    }
}
Name Description Required?
command1 The command that should be run. yes
cwd1 The working directory. Relative paths will be mapped to the workspace root folder. Default: (workspace root folder) no
silent Do not write result to output. Default: (true) no
wait Wait until command has been executed or not. Default: (true) no

1 supports placeholders

button

Name Description Required?
color1 The RGB text color. no
isRight Display button one the right side or not. Default: (false) no
priority A (numeric) value that defines the priority, the button should be displayed with. no
text1 2 The (display) text. no
tooltip1 The tooltip text. no

1 supports placeholders
2 supports icons

⚠️ **GitHub.com Fallback** ⚠️