Coder Social home page Coder Social logo

rtconfig's Introduction

Real Time Config 实时配置

NPM version Build Status Coverage Status

背景

服务变更配置时通常需要重启进程,但这样会导致服务中断,一些事务性的处理会受到影响,严重时会导致数据异常。为此写了一个通过侦测文件修改时间刷新配置的小工具。

需求场景

  • 标识服务器升级中,停止写入操作;
  • 按运营需要调整数值;
  • 动态切换连接服务器。

使用

安装

$ npm install rtconfig --save

示例

var RealtimeConfig = require('rtconfig');

var config = new RealtimeConfig('config/config.js');

app.get('commit', function (req, res) {
	if (config.updating) {
		res.json({
			error: '正在升级,请稍后重试。'
		});
		return;
	}
	// ...
});

小成本修改

修改前

const config = require('./config.json');

修改后

const config = new (require('rtconfig'))('./config.json');

已投入实战,请放心使用

License

MIT © zswang

rtconfig's People

Contributors

zswang avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.