Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
Add timeout option to shutdown the idle apps
  • Loading branch information
layerssss committed Jun 24, 2017
1 parent ac8f8cb commit f55c653
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/bnb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Bnb {
this._sessions = [];
this._onStateChange = onStateChange;
this._applicationLocks = {};
this._applicationTimers = {};
this._terminals = {};

if (!this._state.applications) {
Expand Down Expand Up @@ -133,6 +134,15 @@ class Bnb {
}

_ensureApplicationUp(application) {
if (application.timeout) {
if (this._applicationTimers[application.id]) clearTimeout(this._applicationTimers[application.id]);

this._applicationTimers[application.id] = setTimeout(()=> {
this._ensureApplicationDown(application);
delete this._applicationTimers[application.id];
}, application.timeout * 1000);
}

return this._lockApplication(application, () => {
var terminal = this._terminals[application.name];
if (terminal) return;
Expand Down Expand Up @@ -216,6 +226,11 @@ class Bnb {
}

_ensureApplicationDown(application) {
if (this._applicationTimers[application.id]) {
clearTimeout(this._applicationTimers[application.id]);
delete this._applicationTimers[application.id];
}

return this._lockApplication(application, () => {
var applicationDown = false;
var terminal = this._terminals[application.name];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnb",
"version": "1.0.2",
"version": "1.0.3",
"description": "Bnb takes care of launching your web app on your development machine.",
"main": "bin/app.js",
"scripts": {
Expand Down
25 changes: 24 additions & 1 deletion static/application_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ApplicationForm extends React.Component {
command: '',
port: 2000 + Math.floor(Math.random() * 1000),
out: '',
timeout: '',
dir: '',
env: {},
envSearch: '',
Expand Down Expand Up @@ -43,6 +44,7 @@ class ApplicationForm extends React.Component {
command: this.state.command,
port: this.state.port,
out: this.state.out,
timeout: this.state.timeout,
dir: this.state.dir,
env: this.state.env
});
Expand Down Expand Up @@ -114,7 +116,7 @@ class ApplicationForm extends React.Component {
},
createElement(
ControlLabel, {},
'Ouput path (optional):'
'Output path (optional):'
),
createElement(
FormControl, {
Expand All @@ -126,6 +128,27 @@ class ApplicationForm extends React.Component {
}
)
),
createElement(
FormGroup, {
controlId: `${this.id}_timeout`,
validationState: 'success'
},
createElement(
ControlLabel, {},
'Timeout (seconds before shutting the application down, optional):'
),
createElement(
FormControl, {
type: 'number',
min: 0,
step: 60,
value: this.state.timeout,
onChange: ev => this.setState({
timeout: Number(ev.target.value) || ''
})
}
)
),
createElement(
FormGroup, {
controlId: `${this.id}_port`,
Expand Down

0 comments on commit f55c653

Please sign in to comment.