Skip to content

Commit

Permalink
[v2.1.8]: added ability to disable worker logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanschwarz committed Feb 22, 2021
1 parent a0ab80e commit 13dc6fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ Both in-memory and persistent tasks are available at the same time, and can be u

## prototype

`constructor(taskMap: Object, { port: Integer, maxAvailableWorkers: Integer, refreshRate: Integer, inMemoryOnly: Boolean, messageBroker: function })`
`constructor(taskMap: Object, { port: Integer, maxAvailableWorkers: Integer, refreshRate: Integer, inMemoryOnly: Boolean, messageBroker: function, logs: String })`
- `taskMap`: a map of functions associated to a `taskType`
- `maxAvailableWorkers`: maximum number of child process (cores), default is set to system maximum
- `port`: server port for child process servers, default set to `3008`
- `refreshRate`: Worker pool refresh rate (in ms), default set to `1000`
- `inMemoryOnly`: force the cluster to only pull jobs from the in-memory task queue.
- `messageBroker` is optional, default set to null (see IPC section)<br>
- `logs`: is one of `['all', 'error']`, default sets to `all` : if set to `'error'`, will only show the errors and warning logs.

`Cluster.isMaster()`: `true` if this process is the master<br/>

Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'nschwarz:cluster',
version: '2.1.7',
version: '2.1.8',
summary: 'native nodejs clusterization for meteor server',
git: 'https://github.com/nathanschwarz/meteor-cluster.git',
documentation: 'README.md'
Expand Down
9 changes: 8 additions & 1 deletion src/Cluster/ChildProcess.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const debug = Npm.require('debug')
import StaticCluster from './StaticCluster'
const process = require('process')
import TaskQueue from '../TaskQueue'
import ChildWorker from '../Worker/ChildWorker'

class ChildProcess extends StaticCluster {
constructor(taskMap) {
constructor(taskMap, { logs = 'all' } = {}) {
super()
Meteor.startup(() => {
TaskQueue.registerTaskMap(taskMap)
})
// enable / disable logs
if (logs === 'all') {
debug.enable('nschwarz:cluster:*')
} else {
debug.enable('nschwarz:cluster:ERROR*,nschwarz:cluster:WARNING*')
}
// register listeners if this process is a worker
process.on('message', ChildWorker.onMessageFromMaster)
process.on('disconnect', ChildWorker.onDisconnect)
Expand Down
2 changes: 1 addition & 1 deletion src/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const errorLogger = debug('nschwarz:cluster:ERROR\t')
logger.log = console.log.bind(console)
warnLogger.log = console.warn.bind(console)

debug.enable('nschwarz:cluster*')
debug.enable('nschwarz:cluster:ERROR*,nschwarz:cluster:WARNING*')

export { logger, warnLogger, errorLogger }

0 comments on commit 13dc6fb

Please sign in to comment.