0.2.0 • Published 6 years ago

@cfware/queue_log-mysql v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@cfware/queue_log-mysql

Travis CI Coverage Status Greenkeeper badge NPM Version NPM Downloads MIT

CFWare queue_log mysql writer

Install @cfware/queue_log-mysql

This module requires node.js 8 or above.

npm i --save @cfware/queue_log-mysql

Usage

const queue_log = require('@cfware/queue_log-mysql');

class QueueManager {
	constructor() {
		this.queue_log = new queue_log({
			/* Default is 'P001', used as value of partition column. */
			partition: 'P001',
			/* Default is least significant part of hostname, used as value of serverid column. */
			serverid: 'serverid',
			/* Default: 'queue_log', the table we insert to. */
			table_name: 'queue_log',
			/* Override default settings used by require('mysql').createPool.
			 * The default database is queuemetrics.
			 */
			mysql: {},
		});

		process.on('SIGTERM', () => this.queue_log.end().catch(() => {}));
	}

	async writeQueueLog(time_id, call_id, queue, agent, verb, data1, data2, data3, data4, data5) {
		/* This is a pointless example.  In real life a queue manager would retrieve some
		 * data from a channel or other object. */
		try {
			await this.queue_log.writeEntry(time_id, call_id, queue, agent, verb, data1, data2, data3, data4, data5);
		} catch (err) {
			/* mysql write failed, record to a file. */
		}
	}
}

Running tests

Tests are provided by eslint and mocha. Tests require access to a test mysql or mariadb daemon. The test database server must have a queuemetrics database and a queuelogd user as defined by sampledb/qm.sql.

Default test configuration:

npm config set @cfware/queue_log-mysql:dbhost 'localhost'
npm config set @cfware/queue_log-mysql:dbprivuser 'root'
npm config set @cfware/queue_log-mysql:dbprivpassword ''

These settings can be changed to use a different server or to use an account less privileged than root. The priv account must have SELECT and DELETE access to the queuemetrics.queue_log table.

Once the database is created and a privileged account configured the tests can be run:

npm install
npm test