npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elasticsearch-cron

v1.0.0

Published

A utility for scheduling elasticsearch queries

Downloads

27

Readme

elasticsearch-cron

Description

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

Coverage Status Dependencies up to date

Features

  • Generalized, pluggable architecture.
  • Configurable, automatic discovery of cluster nodes
  • Persistent, Keep-Alive connections
  • Load balancing (with pluggable selection strategy) across all available nodes.
  • Takes all native client config

Use in Node.js

npm install elasticsearch-cron

NPM Stats

Supported Elasticsearch Versions

Supporting Elasticsearch Version 0.90 to 5.0-prerelease

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

Examples

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}`);
})

Supported cron format

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ 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

Contributing

We accept contributions via Pull Requests on Github.

Pull Requests

  • 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.

Issues

Check issues for current issues.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.