Skip to content

Commit

Permalink
Make open source and develop ISO
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Alza committed Oct 10, 2024
1 parent dd85a37 commit e3021fd
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 71 deletions.
28 changes: 14 additions & 14 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ deploy-job:
environment:
name: open-source
script:
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/translation
# - gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/reporting
# - gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/token-broker
# - gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/translation
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/reporting
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/token-broker
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/cleanup
- gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/telemetry
# - gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/authentication
# - gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/detect-text
# - gcloud builds submit .
# - cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/pdf-to-image
# - gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/telemetry
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/authentication
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/detect-text
- gcloud builds submit .
- cd /builds/petranslate/TradEmploi-backend/translation-app-assessment/backend/pdf-to-image
- gcloud builds submit .
only:
refs:
- master
31 changes: 15 additions & 16 deletions translation-app-assessment/backend/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ app.use(cors(corsOptions));
const projectId = process.env.GCP_PROJECT

// Call initializeFirebase during startup
initializeFirebase();
initializeFirebase().then();

// Function to write monitoring "heartbeat" that cleanup has run
const writeMonitoring = async () => {
Expand Down Expand Up @@ -75,8 +75,8 @@ const writeMonitoring = async () => {
}
return monitoring.createTimeSeries(request)
}
app.get('/', async (req, res) => {
console.log("hello");
app.get('/', async (_req, _res) => {
console.log(`⚡️[server]: cleanup server is running on port ${port}`)
})

app.post('/', async (req, res, next) => {
Expand All @@ -92,25 +92,25 @@ app.post('/', async (req, res, next) => {
deletionPromises.push(collection.doc(docSnapshot.id).delete())
}
await Promise.all(deletionPromises)
if(process.env.ID_BOT !== undefined) await cleanRatesFromBot();
if (process.env.ID_BOT !== undefined) await cleanRatesFromBot();
await writeMonitoring()
console.log(`deleted chats, size:${querySnapshot.size}`)

await createLanguagesFromRates();
await deleteInactiveUsers();
res.status(204).send()
} catch(e) {
} catch (e) {
next(e)
}
})

app.use(function (err, req, res, /*unused*/ next) {
app.use(function (err, req, res, _next) {
console.error(err)
res.status(500)
res.send({ error: err })
})

const port = process.env.PORT || 8083
const port = process.env.PORT || 8080
app.listen(port, () => {
console.log(`listening on port ${port}`)
})
Expand Down Expand Up @@ -153,11 +153,11 @@ const buildkpi = (chat, roomId) => {
messages.length > 0 ? getConversation(messages, members.length) : {}
const device = getDevice(members, chat.support)
return messages.length > 0 ? {
day: new Date(messages[0].date),
roomId: roomId,
conversation: conversation,
device: device,
}
day: new Date(messages[0].date),
roomId: roomId,
conversation: conversation,
device: device,
}
: {}
}

Expand Down Expand Up @@ -351,9 +351,8 @@ async function createLanguagesFromRates() {
const mapLanguages = languagesSelected.filter(l => l).reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());
const languagesSorted = new Map([...mapLanguages.entries()].sort((a, b) => b[1] - a[1]));
Array.from(languagesSorted.keys()).forEach(isoCode => {
createLanguage(isoCode, languagesSorted.get(isoCode), langaugesAverageRate.get(isoCode));
}
);
createLanguage(isoCode, languagesSorted.get(isoCode), langaugesAverageRate.get(isoCode));
});
console.log(`language documents created, size: ${languagesSorted.size}`);
}

Expand All @@ -373,7 +372,7 @@ async function deleteInactiveUsers() {
const oneYearAgo = Date.now() - 365 * 24 * 60 * 60 * 1000;
try {
let usersDeleted = 0;
let nextPageToken;
let nextPageToken = '';

do {
const result = await auth.listUsers(1000, nextPageToken);
Expand Down
12 changes: 5 additions & 7 deletions translation-app-assessment/backend/reporting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
"node": "14"
},
"main": "dist/index.js",
"dependencies": {
"@types/cron": "^1.7.2",
"apollo-server-express": "^2.18.2",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"apollo-server-express": "^2.26.2",
"axios": "^1.7.7",
"cron": "^1.8.2",
"date-fns": "^4.1.0",
"express": "^4.17.1",
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0",
"graphql": "^15.3.0",
"graphql": "^15.9.0",
"typescript": "^4.1.5"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.4",
"firebase-functions-test": "^0.1.6",
"tslint": "^5.12.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as admin from "firebase-admin"
import {formatDate} from "../data/utils"
import {formatDate} from "./utils"

export const rates = async () => {
if (!admin.apps.length) {
Expand Down Expand Up @@ -71,7 +71,7 @@ const buildRate = (r: any) => {
user: r.user ? r.user : "",
agency: r.agency ? r.agency : "",
typeSTT: r.typeSTT ? r.typeSTT: "",
isTradTonDoc: r.isTradTonDoc ? r.isTradTonDoc: "",
isTradTonDoc: r.isTradTonDoc !== "" ? Boolean(r.isTradTonDoc) : false,
nbTranslatedCharacters: r.nbTranslatedCharacters ? r.nbTranslatedCharacters : 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ApolloServer} from 'apollo-server-express';

function gqlServer() {
const app = express();
const port: number = process.env.PORT ? +process.env.PORT : 8080;
const port: number = 8081;

const apolloServer = new ApolloServer({
context: async () => {
Expand All @@ -17,7 +17,7 @@ function gqlServer() {
playground: true
}) as any;

apolloServer.applyMiddleware({app, path: '/', cors: true});
apolloServer.applyMiddleware({app, path: '/graphql', cors: true});
app.listen(port, '0.0.0.0');
return app;
}
Expand Down
Loading

0 comments on commit e3021fd

Please sign in to comment.