This package provides the following services:
service-cron
Provides cronjob-inspired interface through a web worker
This package provides a service that let's you schedule Atom commands using a cron-inspired interface. It utilizes a Web Worker to keep your main-thread as free as possible.
Installation
apm
Install service-cron
from Atom install view or use the command-line equivalent:
$ apm install service-cron
Using Git
Change to your Atom packages directory:
Windows
# Powershell
$ cd $Env:USERPROFILE\.atom\packages
:: Command Prompt
$ cd %USERPROFILE%\.atom\packages
Linux & macOS
$ cd ~/.atom/packages/
Clone the repository as service-cron
:
$ git clone https://github.com/idleberg/atom-service-cron service-cron
Install dependencies:
cd service-cron && npm install
Build source:
npm run build
Usage
To consume the service in your package, add the following to your package.json
:
"consumedServices": {
"service-cron": {
"versions": {
"0.1.0": "consumeCron"
}
},
"package-deps": [
{
"name": "service-cron"
}
]
}
Install atom-package-deps
to handle the package dependency:
npm install atom-package-deps
Next up, let's create a package:
import { CompositeDisposable, Disposable } from 'atom';
export default {
// Consume the service
consumeCron(cronService) {
this.cron = cronService;
return new Disposable(() => {
this.cron = null;
});
},
// Optional: Add a demo command
activate() {
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.commands.add('atom-workspace', {
"my-package:demo-command": async () =>
await this.demoCommand(),
})
);
},
async demoCommand() {
// Displays the about dialog at noon
await this.cron('0 12 * * *', {
commands: ['application:about']
});
}
};
Again, this is an experiment. I'm not sure where this is going, but I'm looking forward to your feedback!
License
This work is licensed under the MIT License