1.0.5 • Published 7 years ago

@octopod-service/notifier v1.0.5

Weekly downloads
1
License
Unlicense
Repository
github
Last release
7 years ago

Notifier for octopod

npm Version

Install

npm install @octopod-service/notifier

Usage

// TypeScript
import * as notifier from '@octopod-service/notifier'
// JavaScript
const notifier = require('@octopod-service/notifier');

const notifierService = new notifier.NotifierService('http://...');

// Set option
notifierService.operations.push({
    type: 'write-file',
    settings: {
        path: '...'
    }
});

notifierService.types['write-file'] = function(type /* : DestinationType*/, data /* : Notification*/, callback /* : () => void*/)
{
    if(!type.settings.path)
    {
        this.error('Error in "write-file"', 'type.settings.path is not defined');
        return callback();
    }

    const retry = () => {
        require('fs').writeFile(type.settings.path, JSON.stringify(data), (e) => {
            if(!e)
                return callback(); // Success!

            this.error('Error in "write-file"', e);
            return setTimetout(() => retry(), type.retryTimeout ? type.retryTimeout : 10000); // If failed, retry later
        })
    }

    retry();
}

notifierService.start();

Call

this.writeToService<Notification>('notifier', 'notify', {
    title: 'title',
    body: 'body\r\nbody.',
    notify: {
        node: this.uid,
        type: this.options.username
    }
}, () => { });
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago