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

fix(contributions) : ajout d'un titre par défaut si pas du titre ou si c'est un 1er publication #1477

Merged
merged 7 commits into from
Sep 30, 2024
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ docker-compose up -d hasura minio elasticsearch createbuckets
#### 5. Run ingester in development mode

```sh
DISABLE_LIMIT_EXPORT=true DISABLE_AGREEMENTS=true DISABLE_SITEMAP=true HASURA_GRAPHQL_ENDPOINT="http://localhost:8080/v1/graphql" HASURA_GRAPHQL_ADMIN_SECRET="admin1" ELASTICSEARCH_URL_PREPROD="http://localhost:9200" ELASTICSEARCH_URL_PROD="http://localhost:9200" SITEMAP_DESTINATION_FOLDER="sitemap" SITEMAP_NAME="sitemap.xml" SITEMAP_ENDPOINT="http://localhost:3001/api/sitemap" AGREEMENTS_DESTINATION_FOLDER="agreements" AGREEMENTS_DESTINATION_NAME="index.json" BUCKET_DEFAULT_FOLDER="default" BUCKET_DRAFT_FOLDER="draft" BUCKET_PUBLISHED_FOLDER= BUCKET_PREVIEW_FOLDER="preview" BUCKET_ACCESS_KEY="MINIO_ACCESS_KEY" BUCKET_ENDPOINT=http://localhost:9000 BUCKET_NAME="cdtn" BUCKET_SECRET_KEY="MINIO_SECRET_KEY" BUCKET_REGION="us-east-1" CDTN_ADMIN_ENDPOINT="http://localhost:8080/v1/graphql" ELASTICSEARCH_INDEX_PREPROD="cdtn-v2" ELASTICSEARCH_INDEX_PROD="cdtn-v2" FETCH_PAGE_SIZE=1000 FETCH_JOB_CONCURRENCY=5 yarn workspace export-elasticsearch dev
DISABLE_LIMIT_EXPORT=true DISABLE_AGREEMENTS=true DISABLE_SITEMAP=true DISABLE_COPY=true HASURA_GRAPHQL_ENDPOINT="http://localhost:8080/v1/graphql" HASURA_GRAPHQL_ADMIN_SECRET="admin1" ELASTICSEARCH_URL_PREPROD="http://localhost:9200" ELASTICSEARCH_URL_PROD="http://localhost:9200" SITEMAP_DESTINATION_FOLDER="sitemap" SITEMAP_NAME="sitemap.xml" SITEMAP_ENDPOINT="http://localhost:3001/api/sitemap" AGREEMENTS_DESTINATION_FOLDER="agreements" AGREEMENTS_DESTINATION_NAME="index.json" BUCKET_DEFAULT_FOLDER="default" BUCKET_DRAFT_FOLDER="draft" BUCKET_PUBLISHED_FOLDER= BUCKET_PREVIEW_FOLDER="preview" BUCKET_ACCESS_KEY="MINIO_ACCESS_KEY" BUCKET_ENDPOINT=http://localhost:9000 BUCKET_NAME="cdtn" BUCKET_SECRET_KEY="MINIO_SECRET_KEY" BUCKET_REGION="us-east-1" CDTN_ADMIN_ENDPOINT="http://localhost:8080/v1/graphql" ELASTICSEARCH_INDEX_PREPROD="cdtn-v2" ELASTICSEARCH_INDEX_PROD="cdtn-v2" FETCH_PAGE_SIZE=1000 FETCH_JOB_CONCURRENCY=5 yarn workspace export-elasticsearch dev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai juste rajouté DISABLE_COPY=true

```

- `DISABLE_LIMIT_EXPORT` is used to disable the limit to run two export in less than one hour
Expand Down
1 change: 1 addition & 0 deletions shared/types/src/hasura/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type ContributionStatus = {

export type ContributionsAnswers = {
id: string;
cdtnId: string | null;
content: string | null;
description: string | null;
content_type: ContributionContentType;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ContributionDocumentJson,
DocumentElasticWithSource,
ExportEsStatus,
} from "@socialgouv/cdtn-types";
import { context } from "../context";
import { gqlClient } from "@shared/utils";
Expand All @@ -17,10 +16,6 @@ query fetchContributionsInDocuments($updated_at: timestamptz!) {
cdtnId: cdtn_id
contribution {
id
statuses(where:{status: {_eq: "TO_PUBLISH"}}, order_by: {created_at: desc}, limit: 1) {
status
createdAt: created_at
}
}
}
}
Expand All @@ -30,24 +25,6 @@ interface HasuraReturn {
documents: [DocumentElasticWithSource<ContributionDocumentJson>] | undefined;
}

export function filterContributionDocumentsToPublish(
latestExportEs: Partial<ExportEsStatus> | undefined,
contributionDocs:
| DocumentElasticWithSource<ContributionDocumentJson>[]
| undefined
): DocumentElasticWithSource<ContributionDocumentJson>[] | undefined {
return contributionDocs?.filter((doc) => {
const exportDate = latestExportEs?.created_at
? new Date(latestExportEs.created_at).getTime()
: 0;
const statusDate = doc.contribution?.statuses?.length
? new Date(doc.contribution.statuses[0].createdAt).getTime()
: 0;

return statusDate > exportDate;
});
}

export async function fetchContributionDocumentToPublish(
isProd: boolean
): Promise<DocumentElasticWithSource<ContributionDocumentJson>[] | undefined> {
Expand Down Expand Up @@ -75,8 +52,5 @@ export async function fetchContributionDocumentToPublish(
throw res.error;
}

return filterContributionDocumentsToPublish(
lastCompletedExportEsStatus,
res.data?.documents
);
return res.data?.documents;
}
41 changes: 19 additions & 22 deletions targets/export-elasticsearch/src/services/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ export class ExportService {
environment,
Status.running
);
const envName =
environment === Environment.preproduction
? "Préproduction"
: "Production";
try {
if (!process.env.DISABLE_INGESTER) {
const startMessage = `**${envName}:** mise à jour lancée par *${exportEs.user?.name}* 🚀`;
await sendMattermostMessage(
startMessage,
process.env.MATTERMOST_CHANNEL_EXPORT
);
logger.info(startMessage);
if (environment === Environment.preproduction) {
await sendMattermostMessage(
`**Préproduction:** mise à jour lancée par *${exportEs.user?.name}* 😎`,
process.env.MATTERMOST_CHANNEL_EXPORT
);
await runWorkerIngesterPreproduction();
} else {
await sendMattermostMessage(
`**Production:** mise à jour lancée par *${exportEs.user?.name}* 🚀`,
process.env.MATTERMOST_CHANNEL_EXPORT
);
await runWorkerIngesterProduction();
}
}
Expand All @@ -66,27 +68,22 @@ export class ExportService {
await this.copyContainerService.runCopy(environment);
}
const exportEsDone = await this.exportRepository.getOne(id);
if (environment === Environment.preproduction) {
await sendMattermostMessage(
`**Préproduction:** mise à jour terminée (${exportEsDone.documentsCount?.total} documents) 😁`,
process.env.MATTERMOST_CHANNEL_EXPORT
);
} else {
await sendMattermostMessage(
`**Production:** mise à jour terminée (${exportEsDone.documentsCount?.total} documents) 🎉`,
process.env.MATTERMOST_CHANNEL_EXPORT
);
}

const message = `**${envName}:** mise à jour terminée (${exportEsDone.documentsCount?.total} documents) 🎉`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai reformatté les messages pour les avoir aussi dans les logs pour aider au debug

logger.info(message);
await sendMattermostMessage(
message,
process.env.MATTERMOST_CHANNEL_EXPORT
);

return await this.exportRepository.updateOne(
id,
Status.completed,
new Date()
);
} catch (e: any) {
await sendMattermostMessage(
environment === Environment.preproduction
? " La mise à jour de la préproduction a échouée. 😢"
: "La mise à jour de la production a échouée. 😭",
`⚠️ **${envName}:** La mise à jour a échouée. ⚠️`,
process.env.MATTERMOST_CHANNEL_EXPORT
);
return await this.exportRepository.updateOne(
Expand Down
1 change: 1 addition & 0 deletions targets/frontend/__mocks__/@codegouvfr/react-dsfr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module.exports = {
},
},
},
spacing: jest.fn()
},
};
Loading
Loading