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

chronometer

v0.0.1

Published

a hive-mvc mixin to fire off events at given intervals

Downloads

11

Readme

Chronometer

THis module is a basic chron imitator. It creates a manager, Chron_Manager, that fires off a time every minute (though not necessarily every 60 seconds) and added events are executed with given intervals.

More complex intervals can be expressed as a function that recievs the time as a moment instance.

The cronomter mixin fires off at -1000... (very negative number) so other mixins can use it.

Installing Chronometer in hive-mvc

put the chronometer file in any resources/mixins folder. you should not have more than one chronometer in a hive-mvc project; it is written to only install itself if there is not a chronometer in the apiary's config already.

Using Chronomter outside of hive-mvc.

the export of chronometer is a function for use in hive-mvc; however it does have a Chronometer constructor as a property so you can just call;

    var my_sandbox = {};
    var my_chron = new (require('./chronometer.js'))Chronometer(my_sandbox);

The single argument to Chronometer(Chron_Manager) isn't used any way by Chronometer.

Example mixin using Chronometer:


    var _ = require('underscore');
    var util = require('util');
    var path = require('path');
    var fs = require('fs');

    /* ------------ CLOSURE --------------- */
    var EVERY_SIX_HOURS = 60 * 12;

    /** ********************
     * Purpose: poll local events every 12 hours
     * @return void
     */

    /* -------------- EXPORT --------------- */

    module.exports = function (apiary, cb) {

        function poll() {
            var tmsapi_model = apiary.model('tmsapi');
            var location_model = apiary.model('locations');

            location_model.locations.forEach(function(loc){

                tmsapi_model.poll_api(loc.zip, _.identity);
            })

        }

        cb(null, {
            name: 'poll_events',
            weight: 10000,
            respond: function (done) {
                var chronometer = apiary.get_config('chronometer');
                chronometer.add_time_listener('poll data', poll, EVERY_SIX_HOURS);
                poll();
                done();
            }
        }); // end callback
    }

note that the action is called with two arguments:

time {moment} manager {Chron_Manager}

so an action can ass other listeners, cancel listeners, uncancel listeners, etc.

Each listener has an active field. If its active is set to false a listener will never trigger. If that's not good enough the ChronEvent's _respond (NOT respond) listener can be removed from the manager.

More custom responses

If for some reason you need a more custom handler for time events, you can manually listen for the time (time) event that the manager emits.

The last of the timelords

The manager's clock can be started and stopped; you can call manager.stop_clock() or manager.start_clock. This is useful for unit tests or other scenarios where you want to control the execution of long tasks.

You could, for instnace, stop the clock and fire off times at whatever interval you please -- every five minutes, every 15 minutes, every hour....

Why this doesn't use/emulate CHRON

I find the notation of Chron overly arcane. I figured its best to just handle the "Extreme" scenarios:

  1. You want to do something on a regular interval (pretty common)
  2. You want to do something on a strange interval (for which you can write a function).

Giving you a function that interprets an absolute time really frees you up. You can execute on a given set of absolute dates, or even pull a set of times from a data feed and execute on those times.

If the Chron system of notation works for you, using node-chron is pretty easy, and chronometer is not the module for you.