
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
elasticsearch-cron
Advanced tools
An event driven utitily for scheduling elasticsearch jobs extending the capabilities of the official elasticseach javascript client. Ever wanted to query elastic search periodically and perform a task with the result or want to watch a particular keyword but considers elaticwatch too complex and expensive
npm install elasticsearch-cron
Elasticsearch-cron provides support for, and is regularly tested against, Elasticsearch releases 0.90.12 and greater. We also test against the latest changes in several branches in the Elasticsearch repository. To tell the client which version of Elastisearch you are using, and therefore the API it should provide, set the apiVersion
config param. More info
Create a client instance
const EsCron = require('elasticsearch-cron');
const client = new EsCron({
host: 'localhost:9200',
log: 'trace'
});
Scheduling a cron search
syntax
let search = client.search(query,
cron-pattern,
size(defaults to 1000),
index(optional),
type(optional))
example. query every 30seconds
let search = client.search({
"match":
{
"log": "BitunnelRouteException"
}
},
'*/30 * * * * *');
This task intelligently runs in the background varying the time range for queries in each run. See internal query structure
{
query: {
"bool": {
"must": [
{
"match": {
"log": "BitunnelRouteException"
}
},
{
"range": {
"@timestamp": {
"gte": lastRun,
"lte": currentTime
}
}
}
]
}
}
}
It will query elasticsearch for all changes since the last run date. Eg.
If you set a cron task to run at 12am
everyday. The last run for a job on 12am monday
will be 12am sunday
. That way, all the changes in the 24-hour is captured.
Parse result on each run
search.on('run', (data) => {
console.log(`Came back with the result ${data}`);
});
Catch errors
search.on('error', (ex) => {
console.log(`An error occured, ${ex}`);
})
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
Supports mixed use of ranges and range increments (L, W and # characters are not supported currently). See tests for examples. See crontab for more information
We accept contributions via Pull Requests on Github.
Document any change in behaviour - Make sure the README.md
and any other relevant documentation are kept up-to-date.
Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option.
Create feature branches - Don't ask us to pull from your master branch.
One pull request per feature - If you want to do more than one thing, send multiple pull requests.
Send coherent history - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
Check issues for current issues.
The MIT License (MIT). Please see LICENSE for more information.
FAQs
A utility for scheduling elasticsearch queries
The npm package elasticsearch-cron receives a total of 1 weekly downloads. As such, elasticsearch-cron popularity was classified as not popular.
We found that elasticsearch-cron demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.