Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use @socialgouv/codes-naf fix #5 #23

Merged
merged 2 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .k8s/__tests__/__snapshots__/indexing-dev.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ metadata:
apiVersion: batch/v1
kind: Job
metadata:
name: update-index
name: update-index-ccff889
annotations:
app.gitlab.com/app: socialgouv-recherche-entreprises
app.gitlab.com/env: recherche-entreprises-209-gitlab3-dev2
Expand Down
2 changes: 1 addition & 1 deletion .k8s/__tests__/__snapshots__/indexing-preprod.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ metadata:
apiVersion: batch/v1
kind: Job
metadata:
name: update-index
name: update-index-ccff889
annotations:
app.gitlab.com/app: socialgouv-recherche-entreprises
app.gitlab.com/env: recherche-entreprises-209-gitlab3-dev2
Expand Down
2 changes: 1 addition & 1 deletion .k8s/__tests__/__snapshots__/indexing-prod.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ metadata:
apiVersion: batch/v1
kind: Job
metadata:
name: update-index
name: update-index-ccff889
annotations:
app.gitlab.com/app: socialgouv-recherche-entreprises
app.gitlab.com/env: recherche-entreprises-209-gitlab3-dev2
Expand Down
2 changes: 1 addition & 1 deletion .k8s/components/jobs/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const configMap = new ConfigMap({
// create the final job
const job = new Job({
metadata: {
name: "update-index",
name: `update-index-${process.env.CI_COMMIT_SHORT_SHA}`,
},
spec: {
backoffLimit: 3,
Expand Down
4 changes: 3 additions & 1 deletion index/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"start": "node --max_old_space_size=8192 -r ts-node/register src/index.ts",
"build": "NODE_OPTIONS='--max-old-space-size=8192' ncc build src/index.ts -o dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@elastic/elasticsearch": "^7.12.0",
"@socialgouv/codes-naf": "^1.0.5",
"@socialgouv/kali-data": "^2.61.0",
"fast-csv": "^4.3.6",
"p-all": "^3.0.0",
Expand Down
5 changes: 5 additions & 0 deletions index/src/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,8 @@ export const add = async (enterprises: Enterprise[], indexName: string) => {
{ concurrency: 5 }
);
};

export const getDocsCount = async (indexName: string): Promise<number> => {
const stats = await esClient.indices.stats({index: indexName});
return stats.body._all.primaries.docs.count;
}
17 changes: 16 additions & 1 deletion index/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as fs from "fs";
import * as path from "path";
import * as csv from "fast-csv";
import { add, createIndex, updateAlias, deleteOldIndices } from "./elastic";
import {
add,
createIndex,
updateAlias,
deleteOldIndices,
getDocsCount,
} from "./elastic";
import { Enterprise } from "./enterprise";

const ASSEMBLY_FILE = process.env.ASSEMBLY_FILE || "../output/assembly.csv";
Expand Down Expand Up @@ -39,6 +45,15 @@ if (require.main === module) {
// use elastic alias feature to prevent downtimes
createIndex().then(async (indexName) =>
insertEntreprises(indexName)
.then(async () => {
// ensure we have some data
const docsCount = await getDocsCount(indexName);
if (!docsCount) {
throw new Error(`No document created in index ${indexName}, skip aliasing`);
} else {
console.log(`Created ${docsCount} documents in index ${indexName}`);
}
})
.then(() => updateAlias(indexName))
.then(() => deleteOldIndices(indexName))
);
Expand Down
877 changes: 6 additions & 871 deletions index/src/naf.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lib": ["es2020", "dom"],
"module": "commonjs",
"target": "es2020",

"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
Expand Down
5 changes: 5 additions & 0 deletions index/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
lodash.isundefined "^3.0.1"
lodash.uniq "^4.5.0"

"@socialgouv/codes-naf@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@socialgouv/codes-naf/-/codes-naf-1.0.5.tgz#fa64c00b6299d0d41e1e88a4422ca72cb688e08c"
integrity sha512-unWkbh6qcG/9B+Oa2LsES6+xFYRK+KMyfa+NNszaEE7JYxSAibRnICTEkRUjriufrRXREV0fiB3MR0ytk7uAMA==

"@socialgouv/kali-data@^2.61.0":
version "2.61.0"
resolved "https://registry.yarnpkg.com/@socialgouv/kali-data/-/kali-data-2.61.0.tgz#8e83bca951c99a0cf000c5e8298d309b378d6bcc"
Expand Down