forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[filesystem] run watching in the separate process
Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
- Loading branch information
Showing
11 changed files
with
287 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ examples/*/webpack.config.js | |
.browser_modules | ||
**/docs/api | ||
package-backup.json | ||
.history | ||
.history | ||
.Trash-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/core/src/common/messaging/connection-error-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { Message } from "vscode-jsonrpc"; | ||
|
||
export interface ResolvedConnectionErrorHandlerOptions { | ||
readonly serverName: string | ||
/** | ||
* The maximum amout of errors allowed before stopping the server. | ||
*/ | ||
readonly maxErrors: number | ||
/** | ||
* The maimum amount of restarts allowed in the restart interval. | ||
*/ | ||
readonly maxRestarts: number | ||
/** | ||
* In minutes. | ||
*/ | ||
readonly restartInterval: number | ||
} | ||
|
||
export type ConnectionErrorHandlerOptions = Partial<ResolvedConnectionErrorHandlerOptions> & { | ||
readonly serverName: string | ||
}; | ||
|
||
export class ConnectionErrorHandler { | ||
|
||
protected readonly options: ResolvedConnectionErrorHandlerOptions; | ||
constructor(options: ConnectionErrorHandlerOptions) { | ||
this.options = { | ||
maxErrors: 3, | ||
maxRestarts: 5, | ||
restartInterval: 3, | ||
...options | ||
}; | ||
} | ||
|
||
shouldStop(error: Error, message?: Message, count?: number): boolean { | ||
return !count || count > this.options.maxErrors; | ||
} | ||
|
||
protected readonly restarts: number[] = []; | ||
shouldRestart(): string | undefined { | ||
this.restarts.push(Date.now()); | ||
if (this.restarts.length < this.options.maxRestarts) { | ||
return undefined; | ||
} | ||
const diff = this.restarts[this.restarts.length - 1] - this.restarts[0]; | ||
if (diff <= this.options.restartInterval * 60 * 1000) { | ||
return `The ${this.options.serverName} server crashed ${this.options.maxRestarts} times in the last ${this.options.restartInterval} minutes. | ||
The server will not be restarted.`; | ||
} | ||
this.restarts.shift(); | ||
return undefined; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
|
||
export * from './handler'; | ||
export * from './proxy-factory'; | ||
export * from './connection-error-handler'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import 'reflect-metadata'; | ||
import * as yargs from 'yargs'; | ||
import { ConsoleLogger } from 'vscode-ws-jsonrpc/lib/logger'; | ||
import { createMessageConnection, IPCMessageReader, IPCMessageWriter, Trace } from 'vscode-jsonrpc'; | ||
import { JsonRpcProxyFactory } from '@theia/core'; | ||
import { FileSystemWatcherClient } from '../../common/filesystem-watcher-protocol'; | ||
import { ChokidarFileSystemWatcherServer } from './chokidar-filesystem-watcher'; | ||
|
||
// tslint:disable:no-console | ||
// tslint:disable:no-any | ||
|
||
const options: { | ||
verbose: boolean | ||
} = yargs.option('vebose', { | ||
default: false, | ||
alias: 'v', | ||
type: 'boolean' | ||
}).argv as any; | ||
|
||
const reader = new IPCMessageReader(process); | ||
const writer = new IPCMessageWriter(process); | ||
const logger = new ConsoleLogger(); | ||
const connection = createMessageConnection(reader, writer, logger); | ||
connection.trace(Trace.Off, { | ||
log: (message, data) => console.log(`${message} ${data}`) | ||
}); | ||
|
||
const server = new ChokidarFileSystemWatcherServer(options); | ||
const factory = new JsonRpcProxyFactory<FileSystemWatcherClient>(server); | ||
server.setClient(factory.createProxy()); | ||
factory.listen(connection); | ||
|
||
// FIXME extract the utility function to fork Theia process | ||
if (process.env['THEIA_PARENT_PID']) { | ||
const parentPid = Number(process.env['THEIA_PARENT_PID']); | ||
|
||
if (typeof parentPid === 'number' && !isNaN(parentPid)) { | ||
setInterval(function () { | ||
try { | ||
// throws an exception if the main process doesn't exist anymore. | ||
process.kill(parentPid, 0); | ||
} catch (e) { | ||
process.exit(); | ||
} | ||
}, 5000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.