Skip to content

Commit

Permalink
feat(worker): Add sentry to xapian worker scope
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowbas authored and bas080 committed Nov 13, 2024
1 parent 100b945 commit 3083c20
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 53 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
"rules": {
"@angular-eslint/template/eqeqeq": "warn"
}
},
{
"files": [
"*.js"
],
"parserOptions": {
"ecmaVersion": 2015
},
"extends": [
"eslint:recommended"
],
"env": {
"node": true
}
}
]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ mockserver.log

# CI artifacts
cypress/videos

# environment
src/environments/env.ts

7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ng": "ng",
"appdev": "ng serve --disable-host-check --base-href=/appdev/",
"rmm6dev": "ng serve --disable-host-check --base-href=/appdev/ rmm6",
"start": "ng serve --proxy-config backend-proxy-remote.conf.js runbox7",
"start": "node src/build/gen-env.js && ng serve --proxy-config backend-proxy-remote.conf.js runbox7",
"start-use-mockserver": "ng serve --proxy-config backend-proxy-mock.conf.js --port 4201 runbox7",
"mockserver": "tsc -p e2e/mockserver && node e2e/mockserver/out/mockserver.main.js",
"buildrmm6": "ng build --configuration production --base-href=/app/ rmm6",
Expand Down Expand Up @@ -97,5 +97,8 @@
"tslib": "^2.5.0",
"typescript": "~4.9.5",
"webdriver-manager": "~12.1.9"
},
"peerDependencies": {
"debug": "^2.6.9"
}
}
7 changes: 6 additions & 1 deletion src/app/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

// ADD SENTRY HERE
import { environment } from '../environments/environment'
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: environment.SENTRY_DSN
});
13 changes: 8 additions & 5 deletions src/app/xapian/index.worker.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2022 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

/// <reference lib="webworker.importscripts" />

import '../sentry';

import { Observer, Observable, of, from, AsyncSubject } from 'rxjs';
import { mergeMap, map, filter, catchError, tap, take, bufferCount } from 'rxjs/operators';

Expand Down Expand Up @@ -250,7 +253,7 @@ class SearchIndexService {
}

this.localSearchActivated = false;

return new Observable((observer) => {
console.log('Worker: Closing xapian database');
if (this.api) {
Expand Down
15 changes: 0 additions & 15 deletions src/build/add-sentry.js

This file was deleted.

48 changes: 48 additions & 0 deletions src/build/gen-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node

const Debug = require('debug')
const fs = require('fs');

const target = 'src/environments/env.ts'
const debug = Debug('runbox:gen-env')

debug(`Writing env file to ${target}.`)

const env = [
['SENTRY_DSN', tryCatch(assertString, orNull)],
]

function assertString(input) {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, but received ${typeof input}`);
}
return input;
}

function tryCatch (tryFn, catchFn) {
return value => {
try {
return tryFn(value);
} catch (error) {
return catchFn(error, value)
}
}
}

function orNull () {
return null
}


fs.writeFileSync('src/environments/env.ts', `// This file is auto-generated.
export default ${JSON.stringify(
env.reduce((acc, [name, fn]) => {
acc[name] = fn(process.env[name], name)
return acc
}, {})
, null, 2)}`);

debug(`Wrote env file to ${target}.`)
7 changes: 0 additions & 7 deletions src/build/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,3 @@ if (changelogUpdated) {
console.log('Run the following command to commit it:\n');
console.log('git commit src/app/changelog/changes.ts -em "docs(changelog): Update changelog"');
}

if (!process.env.SENTRY_DSN) {
console.log(chalk.bold.yellow('This build did NOT use Sentry error reporting.'));
console.log('Re-run with SENTRY_DSN environment variable set to enable it');
} else {
execSync('git checkout src/app/sentry.ts');
}
9 changes: 3 additions & 6 deletions src/build/pre-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const fs = require('fs');
console.log('WARNING: Reverting to committed package-lock.json. If that means your changes are lost you should rebuild it.')
cp.execSync('git checkout package-lock.json');

const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json'));
const packageJSON = JSON.parse(fs.readFileSync('package.json'));
// const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json'));
// const packageJSON = JSON.parse(fs.readFileSync('package.json'));

// FIXME: is this necessary? the package.json & package-lock.json format has changed, package.json no longer
// contains a _integrity field, package-lock.json not uses the field packages instead of dependencies.
Expand All @@ -26,10 +26,7 @@ console.log('Updating build timestamp');
const build_time = new Date().toJSON();
fs.writeFileSync('src/app/buildtimestamp.ts', "export const BUILD_TIMESTAMP = '" + build_time + "';\n");

if (process.env.SENTRY_DSN) {
console.log('Adding Sentry setup to app.component.ts');
console.log(cp.execFileSync('node', ['src/build/add-sentry.js']).toString().trim())
}
console.log(cp.execFileSync('node', ['src/build/gen-env.js']).toString().trim())

if (!process.env.SKIP_CHANGELOG) {
console.log('Updating changelog');
Expand Down
15 changes: 9 additions & 6 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

import { environment as defaultEnvironment } from './environment';

export const environment = {
production: true
};
...defaultEnvironment,
production: false
}
16 changes: 7 additions & 9 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import env from './env'

export const environment = {
production: false
...env,
production: false,
};

0 comments on commit 3083c20

Please sign in to comment.