mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-10 23:55:08 +00:00
add db init method, prepare for db testing
This commit is contained in:
parent
f38275a0f9
commit
cec79bdc75
8
app.js
8
app.js
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var http = require('http'),
|
var db = require('./db'),
|
||||||
|
http = require('http'),
|
||||||
nodeStatic = require('node-static'),
|
nodeStatic = require('node-static'),
|
||||||
jade = require('jade'),
|
jade = require('jade'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
@ -72,6 +73,11 @@ Steppy(
|
|||||||
console.log('Server config:', JSON.stringify(app.config, null, 4));
|
console.log('Server config:', JSON.stringify(app.config, null, 4));
|
||||||
|
|
||||||
notifier.init(app.config.notify, this.slot());
|
notifier.init(app.config.notify, this.slot());
|
||||||
|
|
||||||
|
db.init('path/to/db/ignored/for/memdown', {
|
||||||
|
db: require('memdown'),
|
||||||
|
valueEncoding: 'json'
|
||||||
|
}, this.slot());
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
// load all projects for the first time
|
// load all projects for the first time
|
||||||
|
120
db.js
120
db.js
@ -2,72 +2,74 @@
|
|||||||
|
|
||||||
var Steppy = require('twostep').Steppy,
|
var Steppy = require('twostep').Steppy,
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
nlevel = require('nlevel'),
|
nlevel = require('nlevel');
|
||||||
ldb = nlevel.db('path/to/db/ignored/for/memdown', {
|
|
||||||
db: require('memdown'),
|
|
||||||
valueEncoding: 'json'
|
exports.init = function(dbPath, params, callback) {
|
||||||
|
var ldb = nlevel.db(dbPath, params, callback);
|
||||||
|
|
||||||
|
exports.builds = new nlevel.DocsSection(ldb, 'builds', {
|
||||||
|
projections: [
|
||||||
|
{key: {createDate: 1}, value: pickId},
|
||||||
|
{key: {descCreateDate: descCreateDate, id: 1}},
|
||||||
|
{key: {
|
||||||
|
projectName: pickProjectName,
|
||||||
|
descCreateDate: descCreateDate,
|
||||||
|
id: 1
|
||||||
|
}},
|
||||||
|
// note that's unordered projection (coz number is numeric)
|
||||||
|
{key: {
|
||||||
|
projectName: pickProjectName,
|
||||||
|
number: 1,
|
||||||
|
id: 1
|
||||||
|
}}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.builds = new nlevel.DocsSection(ldb, 'builds', {
|
exports.builds._beforePut = function(builds, callback) {
|
||||||
projections: [
|
var self = this,
|
||||||
{key: {createDate: 1}, value: pickId},
|
build;
|
||||||
{key: {descCreateDate: descCreateDate, id: 1}},
|
|
||||||
{key: {
|
Steppy(
|
||||||
projectName: pickProjectName,
|
function() {
|
||||||
descCreateDate: descCreateDate,
|
if (builds.length > 1) {
|
||||||
id: 1
|
throw new Error('Build put hooks work only with single build');
|
||||||
}},
|
}
|
||||||
// note that's unordered projection (coz number is numeric)
|
build = builds[0];
|
||||||
{key: {
|
|
||||||
projectName: pickProjectName,
|
// generate number for build
|
||||||
number: 1,
|
if (!build.number && build.status === 'in-progress') {
|
||||||
id: 1
|
// find last build with number in the same project
|
||||||
}}
|
self.find({
|
||||||
]
|
start: {projectName: build.project.name, descCreateDate: ''},
|
||||||
});
|
filter: function(build) {
|
||||||
|
return 'number' in build;
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
}, this.slot());
|
||||||
|
} else {
|
||||||
|
this.pass([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateIds(self, builds, this.slot());
|
||||||
|
},
|
||||||
|
function(err, prevBuilds) {
|
||||||
|
var prevBuild = prevBuilds[0];
|
||||||
|
if (!build.number && build.status === 'in-progress') {
|
||||||
|
build.number = prevBuild ? prevBuild.number + 1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pass(null);
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
function pickProjectName(build) {
|
function pickProjectName(build) {
|
||||||
return build.project.name;
|
return build.project.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.builds._beforePut = function(builds, callback) {
|
|
||||||
var self = this,
|
|
||||||
build;
|
|
||||||
|
|
||||||
Steppy(
|
|
||||||
function() {
|
|
||||||
if (builds.length > 1) {
|
|
||||||
throw new Error('Build put hooks work only with single build');
|
|
||||||
}
|
|
||||||
build = builds[0];
|
|
||||||
|
|
||||||
// generate number for build
|
|
||||||
if (!build.number && build.status === 'in-progress') {
|
|
||||||
// find last build with number in the same project
|
|
||||||
self.find({
|
|
||||||
start: {projectName: build.project.name, descCreateDate: ''},
|
|
||||||
filter: function(build) {
|
|
||||||
return 'number' in build;
|
|
||||||
},
|
|
||||||
limit: 1
|
|
||||||
}, this.slot());
|
|
||||||
} else {
|
|
||||||
this.pass([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
generateIds(self, builds, this.slot());
|
|
||||||
},
|
|
||||||
function(err, prevBuilds) {
|
|
||||||
var prevBuild = prevBuilds[0];
|
|
||||||
if (!build.number && build.status === 'in-progress') {
|
|
||||||
build.number = prevBuild ? prevBuild.number + 1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pass(null);
|
|
||||||
},
|
|
||||||
callback
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
function generateIds(section, docs, callback) {
|
function generateIds(section, docs, callback) {
|
||||||
Steppy(
|
Steppy(
|
||||||
|
@ -43,9 +43,9 @@ if this.state.build
|
|||||||
| Error:
|
| Error:
|
||||||
span= this.state.build.error.message
|
span= this.state.build.error.message
|
||||||
|
|
||||||
if this.state.build.error.stderr
|
if this.state.build.error.stderr
|
||||||
div stderr:
|
div stderr:
|
||||||
pre= this.state.build.error.stderr
|
pre= this.state.build.error.stderr
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-8
|
.col-md-8
|
||||||
|
5
test/db/concurrent.js
Normal file
5
test/db/concurrent.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Db concurrency', function() {
|
||||||
|
|
||||||
|
});
|
3
test/db/index.js
Normal file
3
test/db/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('./concurrent');
|
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('./commands');
|
require('./commands');
|
||||||
|
require('./db');
|
||||||
require('./scm');
|
require('./scm');
|
||||||
require('./executor');
|
require('./executor');
|
||||||
require('./node');
|
require('./node');
|
||||||
|
Loading…
Reference in New Issue
Block a user