Giter Site home page Giter Site logo

vs-cron's Introduction

[DEPRECATED] vs-cron

Latest Release Installs Rating

Visual Studio Code (VS Code) extension that runs tasks periodically.


The extension is now marked as DEPRECATED ... it is RECOMMENDED to use vscode-powertools by e.GO Digital.

If you have suggestions and other kind of issues for that new extension, feel free to open an issue here.


Table of contents

  1. Install
  2. How to use
  3. Documentation

Install []

Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter:

ext install vs-cron

Or search for things like vs-cron in your editor.

How to use []

Settings []

Open (or create) your settings.json in your .vscode subfolder of your workspace.

Add a cron.jobs section:

{
    "cron.jobs": {
    }
}
Name Description
globals Global data available from everywhere.
jobs One or more job to define.
timeZone The custom default value for the timezone to use.

Jobs []

{
    "cron.jobs": {
        "jobs": [
            {
                "name": "My AutoSave using CronTab format",
                "description": "Saves all opened files all 30 seconds.",
                
                "time": "*/30 * * * * *",
                "action": "workbench.action.files.saveAll"
            },
            
            {
                "name": "My Script using specific date",
                "description": "Runs a script at a specific time.",
                
                "format": "date",
                "time": "1979-09-05 23:09:00",
                "action": {
                    "type": "script",
                    "script": "./my-cron-script.js"
                }
            }
        ]
    }
}
Name Description
action The action to define.
autoStart Run on startup or not. Default: (false)
description The description for the job.
format The format to use. Can be crontab or date. Default: crontab
if One or more conditions (as JavaScript code) that defines if job is available or not.
isFor An optional list of one or more (host)names that job is available for.
maximum The maximum number of executions.
minimum The minimum number of ticks before the job does its first action.
name The (display) name of the job.
platforms One or more platform names the job is for. s. process.platform
runParallel Indicates if this job can be run parallel to another or not. Default: (false)
startDelay The start delay in milliseconds.
time The time value that is used to configure the job. For crontab format, s. cron module
timeZone The custom timezone to use.
validFrom Defines the minumum time the job can be executed.
validUntil Defines the maximum time the job can be executed.
Actions []

The action can be a string, for executing a command, or an object with a type property:

Value Description
command Execute a command.
script Execute a script.
Commands []
{
    "cron.jobs": {
        "jobs": [
            {
                "name": "My AutoSave",
                "description": "Saves all opened files all 5 minutes.",
                
                "time": "*/5 * * * *",
                "action": {
                    "type": "command",
                    "command": "workbench.action.files.saveAll"
                }
            }
        ]
    }
}

The action property has the following format:

Name Description
arguments Optional / required arguments for the command.
command The ID of the command to execute.
Scripts []
{
    "cron.jobs": {
        "globals": "Marcel K! Marcel K! Marcel K!",
    
        "jobs": [
            {
                "name": "My Script",
                "description": "Runs a script every minute.",

                "action": {
                    "type": "script",
                    "script": "./my-cron-script.js",
                    
                    "options": "TM",
                    "state": 23979
                }
            }
        ]
    }
}

The action property has the following format:

Name Description
cached Store script (module) in cache or not. Default: (false)
options Optional data for the execution.
script The path to the script to execute.
state The initial state value for the script.

The ./my-cron-script.js script file must have a public / exported tick() function:

exports.tick = function(args) {
    // access VS Code API (s. https://code.visualstudio.com/Docs/extensionAPI/vscode-api)
    var vscode = require('vscode');

    // access Node.js API provided by VS Code
    // s.  (s. https://nodejs.org/api/)
    var fs = require('fs');

    // access an own module
    var myModule = require('./my-module.js');

    // access a module used by the extension:
    // s. https://mkloubert.github.io/vs-cron/modules/_helpers_.html
    var helpers = args.require('./helpers');

    // access a module that is part of the extentsion
    // s. https://github.com/mkloubert/vs-cron/blob/master/package.json
    var moment = args.require('moment');
    
    // access the global data from the settings
    // 
    // from the example above this is: "Marcel K! Marcel K! Marcel K!"
    var globals = args.globals;

    // access the data from the settings
    // 
    // from the example above this is: "TM"
    var opts = args.options;

    // share / store data (while current session)...
    // ... for this script
    var myState = args.state;  // 23979 at the beginning (s. settings above)
    args.state = new Date();
    // ... with other scripts of this type
    args.globalState['myScript'] = new Date();
    
    // access permanent data storages
    // s. https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/common/memento.ts
    var myAppWideValue = args.appState.get('myAppValue');  // app wide
    args.workspaceState.update('myWorkspaceValue', 'New workspace wide value');  // workspace wide

    // share data between two executions
    var prevVal = args.previousValue;  // data from the previous execution
    args.nextValue = 'This is a value only for the next execution';  // data for the next execution
    
    // registers for a one-time event
    args.once('myEvent', function(v) {
        // 'v' should be 'Anders Hejlsberg'
        // if upcoming 'args.emit()' is called
        args.log("From 'myEvent': " + v);
    });
    
    // emit 'myEvent' event (s. above)
    args.emit('myEvent', 'Anders Hejlsberg');

    // open HTML document in new tab (for reports e.g.)
    args.openHtml('<html>This is an HTML document</html>', 'My HTML document').then(function() {
        // HTML opened
    }, function(err) {
        // opening HTML document failed
    });

    // deploys 'index.html' to 'My SFTP server'
    // s. https://github.com/mkloubert/vs-deploy
    args.deploy(['./index.html'], ['My SFTP server']).then(function() {
        // file deployed
    }, function(err) {
        // deployment failed
    });

    // ...
}

The args parameter uses the JobScriptModuleExecutorArguments interface.

You can return a number (sync execution), a Promise or nothing (default exit code 0).

Commands []

Press F1 to open the list of commands and enter one of the following commands:

Demo How to execute

Name Description Command
Cron Jobs: Restart all jobs Restarts all running jobs. extension.cronJons.restartRunningJobs
Cron Jobs: Restart job Restarts a specific job. extension.cronJons.restartJob
Cron Jobs: Start job Starts a specific job. extension.cronJons.startJob
Cron Jobs: Start all jobs Starts all non-running jobs. extension.cronJons.startNoRunningJobs
Cron Jobs: Stop all running jobs Stops all running jobs. extension.cronJons.stopRunningJobs
Cron Jobs: Stop job Stops a specific job. extension.cronJons.stopJob

Documentation []

The full API documentation can be found here.

vs-cron's People

Contributors

mkloubert avatar

Stargazers

بلال مسلوب avatar Alkor San avatar Aleh Vasilyeu avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

meslubi2021

vs-cron's Issues

Prevent Scheduled Job from attaching its outcome to the last github commit

I have a Scheduled job configured in the pipelines, with CI and PR triggers turned off. When the job is run it picks the latest commit and attaches its outcome to the checks status of that github commit. How can I change this behavior, i.e. so that the cronjob's outcome is reported inside devops, but not ping back github?

The particular cron job is slow, its run affects a multitude of commits, and not necessarily the last one, so it's currently misleading when it pushes its result specifically onto the last commit before the job was scheduled.

Thank you.

p.s. I am actually not sure this is the right place, I was told to report it here at https://developercommunity.visualstudio.com/content/problem/382897/prevent-scheduled-job-from-attaching-its-outcome-t.html - my feeling is that I was sent to a wrong place, as I'm dealing with devops and not vs.

Doc enhancement for command-line usage

Hi,

I am trying to start a shell script with vs-cron and I have a couple of questions.
First off, if I put autoStart to true does it mean that the job will start on boot of the pc or when I open vscode.

Second, I am testing right now if the job is called, here is the definition in my workspace:
`"cron.jobs": {
"jobs": [
{
"name": "Update snap version",
"description": "Updates the version of the snap if it needs to",

            // "autoStart": true,
            "action": {
                "type":"command",
                "command": "workbench.action.terminal.runSelectedText",
                "arguments": [
                    "./watch4changes.sh"
                ]
            }
        }
    ]
}`

To test it I call it with F1 and its name and the script doesn't seem to be called. I tried adding an argument to cd into the path of the file and then do the shell script call to no avail. The shell script is already tested to work. I am on debian with vscode : 1.26.0

example does not work to save all open file

tried this
started the job

i get error every 30 secs
Job 'BBBB' has been STARTED.
[2018-12-01 12:26:00] [ERROR] objects.ConfigJob.startSync().command.action(): Error: command ' workbench.action.files.saveAll' not found
[2018-12-01 12:26:30] [ERROR] objects.ConfigJob.startSync().command.action(): Error: command ' workbench.action.files.saveAll' not found
[2018-12-01 12:27:00] [ERROR] objects.ConfigJob.startSync().command.action(): Error: command ' workbench.action.files.saveAll' not found

      "cron.jobs": {
         "jobs": [
            {
               "name": "BBBB",
               "description": "BBBB",
               "time": "*/30 * * * * *",
               "autoStart": false,
               "action": {
                  "type": "command",
                  "command": " workbench.action.files.saveAll",
               },
            }
         ]
      },

How to run command vscode.workspace.findFiles()

Hi ,
Im trying to use your extension to periodically run the command
vscode.workspace.findFiles

Ive tried something like this. it returns error saying the command is wrong.
image

  "cron.jobs": {
     "jobs": [
         {
           "name": "Auto refresh QuickOpen",
           "description": "Auto refresh the QuickOpen file list periodically",
           "time": "*/5 * * * * *",
           "action": {
              "type": "command",
              "command": "vscode.workspace.findFiles('*')"
           }
        },

Ive tried writing a .js file (i dont know js). i cant even get console.log("aaa") to work.

       {
           "name": "AAAA",
           "description": "AAAA",
           "time": "*/1 * * * * *",
           "action": {
              "type": "script",
              "command": "./derek.js"
        },

exports.tick = function(args) {
// access VS Code API (s. https://code.visualstudio.com/Docs/extensionAPI/vscode-api)
var vscode = require('vscode');
console.log("derek");

// vscode.workspace.findFiles('*')

}

Any advice ...
thx
derek

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.