Skip to content

Commit 92fb4b0

Browse files
Merge pull request #95 from linkedconnections/development
v1.4.1
2 parents d0a95a6 + 59eb43d commit 92fb4b0

File tree

10 files changed

+7098
-28
lines changed

10 files changed

+7098
-28
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
node-version: [18.x, 20.x]
18+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
- run: npm ci
29+
- run: npm run build --if-present
30+
- run: npm run test-ci

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules/
22
coverage
3-
package-lock.json
43
datasets_config.json
54
server_config.json
65
.coveralls.yml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Linked Connections Server
22

3-
[![Coverage Status](https://coveralls.io/repos/github/linkedconnections/linked-connections-server/badge.svg?branch=master)](https://coveralls.io/github/linkedconnections/linked-connections-server?branch=master)
3+
[![Node.js CI](https://github.com/linkedconnections/linked-connections-server/actions/workflows/ci.yml/badge.svg)](https://github.com/linkedconnections/linked-connections-server/actions/workflows/ci.yml)
44

55
Express based Web Server that exposes [Linked Connections](http://linkedconnections.org/) data fragments using [JSON-LD](https://json-ld.org/) serialization format. It also provides a built-in tool to parse [GTFS](https://developers.google.com/tansit/gtfs/reference/) and [GTFS Realtime](https://developers.google.com/transit/gtfs-realtime/) transport dataset feeds into a Linked Connections Directed Acyclic Graph using [GTFS2LC](https://github.com/linkedconnections/gtfs2lc) and fragment it following a configurable predefined size.
66

lib/manager/dataset_manager.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import util from 'util';
3+
import os from 'os';
34
import { deleteAsync as del } from 'del';
45
import child_process from 'child_process';
56
import { CronJob } from 'cron';
@@ -558,8 +559,18 @@ export class DatasetManager {
558559
const k = conn.split('"').indexOf('departureTime') + 2;
559560

560561
// Sort using UNIX sort command
561-
const sortCommand = child_process.exec(`sort -S ${mem} -T ${this.storage}/tmp/ -t '\"' -k ${k} --compress-program=gzip < zcat ${unsorted}`);
562-
return sortCommand.stdout;
562+
const zcat = child_process.spawn('zcat', [`${unsorted}`]);
563+
const sort = child_process.spawn('sort', [
564+
'-S', mem,
565+
'-T', `${this.storage}/tmp/`,
566+
'-t', '\"',
567+
'-k', k,
568+
'--compress-program=gzip',
569+
`--parallel=${os.cpus().length}`
570+
]);
571+
zcat.stdout.pipe(sort.stdin);
572+
// Return readable stream of sorted connections
573+
return sort.stdout;
563574
} catch (err) {
564575
throw err;
565576
}

lib/routes/catalog.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const writeFile = util.promisify(fs.writeFile);
99

1010
export class Catalog {
1111
constructor() {
12+
this._organization = utils.datasetsConfig.organization;
1213
this._storage = utils.datasetsConfig.storage;
1314
this._datasets = utils.datasetsConfig.datasets;
1415
this._serverConfig = utils.serverConfig;
@@ -17,23 +18,25 @@ export class Catalog {
1718
async getCatalog(req, res) {
1819
const agency = req.params.agency;
1920
try {
20-
if (this.datasets.find(d => d.companyName === agency)) {
21+
if (this.datasets && this.datasets.find(d => d.companyName === agency)) {
2122
if (fs.existsSync(`${this.storage}/catalog/${agency}/catalog.json`)) {
2223
res.set({
2324
'Access-Control-Allow-Origin': '*',
2425
'Access-Control-Allow-Headers': '*',
2526
'Content-Type': 'application/ld+json'
2627
});
2728
res.send(await readFile(`${this.storage}/catalog/${agency}/catalog.json`, 'utf8'));
29+
res.status(200);
2830
} else {
2931
const catalog = await this.createCatalog(agency);
30-
writeFile(`${this.storage}/catalog/${agency}/catalog.json`, JSON.stringify(catalog), 'utf8');
32+
await writeFile(`${this.storage}/catalog/${agency}/catalog.json`, JSON.stringify(catalog), 'utf8');
3133
res.set({
3234
'Access-Control-Allow-Origin': '*',
3335
'Access-Control-Allow-Headers': '*',
3436
'Content-Type': 'application/ld+json'
3537
});
3638
res.send(catalog);
39+
res.status(200);
3740
}
3841
} else {
3942
res.set({ 'Cache-Control': 'no-cache' });
@@ -97,9 +100,9 @@ export class Catalog {
97100
"license": "http://creativecommons.org/publicdomain/zero/1.0/",
98101
"accessRights": "access:PUBLIC",
99102
"publisher": {
100-
"@id": utils.datasetsConfig.organization.id,
103+
"@id": this.organization.id,
101104
"@type": "Organization",
102-
"name": utils.datasetsConfig.organization.name
105+
"name": this.organization.name
103106
},
104107
"dataset": []
105108
};
@@ -218,6 +221,10 @@ export class Catalog {
218221
return dist;
219222
}
220223

224+
get organization() {
225+
return this._organization;
226+
}
227+
221228
get storage() {
222229
return this._storage;
223230
}

0 commit comments

Comments
 (0)