提交 922b8717 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fighting with ts-node & watchdog

上级 df8a5c6f
......@@ -12,10 +12,10 @@
* - BUG2: leave event not right: sometimes can not found member (any more, because they left)
*/
import {
Wechaty
, Config
, Room
Config
, Contact
, Room
, Wechaty
, log
} from '../'
......
......@@ -18,8 +18,8 @@ type ConfigSetting = {
DEFAULT_APIHOST: string
DEFAULT_PROFILE: string
DEFAULT_TOKEN: string
DEFAULT_PROTOCOL: string
CMD_CHROMIUM: string
DEFAULT_PROTOCOL: string
CMD_CHROMIUM: string
DEFAULT_PORT: number
port: number
......@@ -119,9 +119,17 @@ Config.puppetInstance = function(instance?: Puppet): Puppet {
return Config._puppetInstance
}
type WatchdogFood = {
data: any
, type?: 'HEARTBEAT' | 'POISON'
, timeout?: number // millisecond
}
// module.exports = Config.default = Config.Config = Config
export default Config
export {
HeadType
Config
, HeadType
, PuppetType
, WatchdogFood
}
......@@ -566,7 +566,7 @@ class Browser extends EventEmitter {
const filename = this.sessionFile
return new Promise((resolve, reject) => {
require('fs').unlink(filename, err => {
fs.unlink(filename, err => {
if (err && err.code !== 'ENOENT') {
log.silly('PuppetWebBrowser', 'cleanSession() unlink session file %s fail: %s', filename, err.message)
}
......
......@@ -17,7 +17,10 @@
// const fs = require('fs')
// const co = require('co')
import Config from '../config'
import {
Config
, WatchdogFood
} from '../config'
import Contact from '../contact'
// import FriendRequest from '../friend-request'
import Message from '../message'
......@@ -85,7 +88,11 @@ class PuppetWeb extends Puppet {
await this.initBridge()
log.verbose('PuppetWeb', 'initBridge() done')
this.emit('watchdog', { data: 'inited' })
const food: WatchdogFood = {
data: 'inited'
, timeout: 120000 // 2 mins for first login
}
this.emit('watchdog', food)
// return this
// }).catch(e => { // Reject
......
......@@ -17,6 +17,7 @@
import log from '../brolog-env'
import Event from './event'
import { WatchdogFood } from '../config'
/* tslint:disable:variable-name */
const Watchdog = {
......@@ -24,21 +25,24 @@ const Watchdog = {
}
// feed me in time(after 1st feed), or I'll restart system
function onFeed({
data = ''
, type = 'HEARTBEAT'
, timeout = 60000 // 60s default. can be override in options but be careful about the number zero(0)
} = {}) {
function onFeed(food: WatchdogFood) {
// change to tape instead of tap
// type = type || 'HEARTBEAT' // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11
// timeout = timeout || 60000 // BUG compatible with issue: node-tap strange behaviour cause CircleCI & Travis-CI keep failing #11
if (!food.type) {
food.type = 'HEARTBEAT'
}
if (!food.timeout) {
food.timeout = 60000 // 60s default. can be override in options but be careful about the number zero(0)
}
if (!this) {
throw new Error('onFeed() must has `this` of instanceof PuppetWeb')
}
const feed = `${type}:[${data}]`
const feed = `${food.type}:[${food.data}]`
log.silly('PuppetWebWatchdog', 'onFeed: %d, %s', timeout, feed)
if (this.currentState() === 'killing'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册