Skip to content

Commit

Permalink
fix: change order when blocking master image sync process
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Aug 7, 2024
1 parent bd43978 commit 8e9efc1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ export async function commandMasterImageRouteHandler(req: Request, res: Response
throw new BadRequestError('A master images synchronization process is already in progress.');
}

await runMasterImagesSynchronizeCommand()
.then(() => {
// todo: maybe additional meta information
memoryCache.set(MemoryCacheID.MASTER_IMAGES, {
now: Date.now(),
}, {
ttl: 1000 * 60 * 15, // 15 minutes
});
});
memoryCache.set(MemoryCacheID.MASTER_IMAGES, {
now: Date.now(),
}, {
ttl: 1000 * 60 * 15, // 15 minutes
});

try {
await runMasterImagesSynchronizeCommand();
} catch (e) {
memoryCache.del(MemoryCacheID.MASTER_IMAGES);
}

return sendAccepted(res);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/server-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"scripts": {
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "rollup -c",
"build": "rimraf ./dist && cross-env NODE_ENV=production npm run build:js && npm run build:types"
"build": "rimraf ./dist && cross-env NODE_ENV=production npm run build:js && npm run build:types",
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
"test:coverage": "npm run test -- --coverage"
},
"dependencies": {
"@ebec/http": "^2.3.0",
Expand Down
33 changes: 33 additions & 0 deletions packages/server-kit/test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx',
'json',
'node',
],
testRegex: '(/unit/.*|(\\.|/)(test|spec))\\.(ts|js)x?$',
testPathIgnorePatterns: [
'writable',
'dist',
'/unit/mock-util.ts',
],
coverageDirectory: 'writable/coverage',
collectCoverageFrom: [
'src/**/*.{ts,tsx,js,jsx}',
],
rootDir: '../',
verbose: true,
};
29 changes: 29 additions & 0 deletions packages/server-kit/test/unit/memory-cache.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { MemoryCache } from '../../src';

describe('memory-cache', () => {
it('should support operations (set,get,has,del)', () => {
const cache = new MemoryCache();
cache.set('foo', { bar: 'baz' }, {
ttl: 1000 * 60 * 15,
});

expect(cache.has('foo')).toBeTruthy();

let value = cache.get('foo');
expect(value).toEqual({ bar: 'baz' });

cache.del('foo');

expect(cache.has('foo')).toBeFalsy();

value = cache.get('foo');
expect(value).toBeUndefined();
});
});

0 comments on commit 8e9efc1

Please sign in to comment.