@codegouvfr/sill
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -13,3 +13,3 @@ "use strict"; | ||
]); | ||
console.log("start compiling"); | ||
console.log("Start compiling"); | ||
const { wikidataSoftwareBySillId, softwareLatestVersionBySillId } = await (async () => { | ||
@@ -33,6 +33,2 @@ const wikidataSoftwareBySillId = {}; | ||
: await getSoftwareLatestVersion({ "repoUrl": wikidataSoftware.sourceUrl }); | ||
console.log({ | ||
"sourceUrl": wikidataSoftware === null || wikidataSoftware === void 0 ? void 0 : wikidataSoftware.sourceUrl, | ||
"latestVersion": softwareLatestVersionBySillId[sillId] | ||
}); | ||
} | ||
@@ -42,3 +38,3 @@ } | ||
})(); | ||
return softwareRows | ||
const compiledData = softwareRows | ||
.map(softwareRow => ({ | ||
@@ -95,2 +91,4 @@ softwareRow, | ||
}); | ||
console.log("Done compiling"); | ||
return compiledData; | ||
}; | ||
@@ -97,0 +95,0 @@ return { compileData }; |
@@ -54,3 +54,3 @@ import type { ReturnType } from "tsafe"; | ||
readWriteSillData: import("redux-clean-architecture/usecasesToFunctions").ThunksToFunctions<{ | ||
triggerPeriodicalNonIncrementalCompilation: () => (dispatch: import("redux-thunk").ThunkDispatch<{ | ||
manuallyTriggerNonIncrementalCompilation: () => (dispatch: import("redux-thunk").ThunkDispatch<{ | ||
readWriteSillData: { | ||
@@ -57,0 +57,0 @@ db: import("./ports/DbApi").Db; |
@@ -13,3 +13,2 @@ import type { Db, WikidataEntry } from "./DbApi"; | ||
}>; | ||
log?: typeof console.log; | ||
}) => Promise<CompiledData<"private">>; | ||
@@ -16,0 +15,0 @@ export type CompiledData<T extends "private" | "public"> = CompiledData.Software<T>[]; |
@@ -169,3 +169,3 @@ import type { PayloadAction } from "@reduxjs/toolkit"; | ||
export declare const thunks: { | ||
triggerPeriodicalNonIncrementalCompilation: () => (dispatch: import("@reduxjs/toolkit").ThunkDispatch<{ | ||
manuallyTriggerNonIncrementalCompilation: () => (dispatch: import("@reduxjs/toolkit").ThunkDispatch<{ | ||
readWriteSillData: State; | ||
@@ -172,0 +172,0 @@ }, { |
@@ -38,3 +38,3 @@ "use strict"; | ||
})); | ||
setInterval(() => dispatch(exports.thunks.triggerPeriodicalNonIncrementalCompilation()), 4 * 3600 * 1000 //4 hour | ||
setInterval(() => dispatch(localThunks.triggerNonIncrementalCompilation({ "triggerType": "periodical" })), 4 * 3600 * 1000 //4 hour | ||
); | ||
@@ -44,33 +44,5 @@ } | ||
exports.thunks = { | ||
"triggerPeriodicalNonIncrementalCompilation": () => async (...args) => { | ||
const [dispatch, getState, extraArg] = args; | ||
const { dbApi, compileData } = extraArg; | ||
const { mutex } = getContext(extraArg); | ||
const dbBefore = (0, structured_clone_1.default)(getState()[exports.name].db); | ||
console.log("here we go"); | ||
const newCompiledData = await compileData({ | ||
"db": dbBefore, | ||
"cache": {} | ||
}); | ||
console.log("after compilation"); | ||
const wasCanceled = await mutex.runExclusive(async () => { | ||
const { db } = getState()[exports.name]; | ||
if (!(0, same_1.same)(dbBefore, db)) { | ||
//While we where re compiling there was some other transaction, | ||
//Re-scheduling. | ||
return true; | ||
} | ||
await dbApi.updateCompiledData({ | ||
newCompiledData, | ||
"commitMessage": "Some Wikidata or other 3rd party source data have changed" | ||
}); | ||
dispatch(exports.actions.updated({ | ||
db, | ||
"compiledData": newCompiledData | ||
})); | ||
return false; | ||
}); | ||
if (wasCanceled) { | ||
await dispatch(exports.thunks.triggerPeriodicalNonIncrementalCompilation()); | ||
} | ||
"manuallyTriggerNonIncrementalCompilation": () => async (...args) => { | ||
const [dispatch] = args; | ||
await dispatch(localThunks.triggerNonIncrementalCompilation({ "triggerType": "manual" })); | ||
}, | ||
@@ -374,2 +346,41 @@ "notifyPushOnMainBranch": (params) => async (...args) => { | ||
}); | ||
}, | ||
"triggerNonIncrementalCompilation": (params) => async (...args) => { | ||
const { triggerType } = params; | ||
const [dispatch, getState, extraArg] = args; | ||
const { dbApi, compileData } = extraArg; | ||
const { mutex } = getContext(extraArg); | ||
const dbBefore = (0, structured_clone_1.default)(getState()[exports.name].db); | ||
const newCompiledData = await compileData({ | ||
"db": dbBefore, | ||
"cache": {} | ||
}); | ||
const wasCanceled = await mutex.runExclusive(async () => { | ||
const { db } = getState()[exports.name]; | ||
if (!(0, same_1.same)(dbBefore, db)) { | ||
//While we where re compiling there was some other transaction, | ||
//Re-scheduling. | ||
console.log("Re-scheduling non incremental compilation, db has changed (probably due to a concurrent transaction)"); | ||
return true; | ||
} | ||
await dbApi.updateCompiledData({ | ||
newCompiledData, | ||
"commitMessage": (() => { | ||
switch (triggerType) { | ||
case "periodical": | ||
return "Periodical update: Some Wikidata or other 3rd party source data have changed"; | ||
case "manual": | ||
return "Manual trigger: Some data have changed since last compilation"; | ||
} | ||
})() | ||
}); | ||
dispatch(exports.actions.updated({ | ||
db, | ||
"compiledData": newCompiledData | ||
})); | ||
return false; | ||
}); | ||
if (wasCanceled) { | ||
await dispatch(localThunks.triggerNonIncrementalCompilation(params)); | ||
} | ||
} | ||
@@ -376,0 +387,0 @@ }; |
{ | ||
"name": "@codegouvfr/sill", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "The backend of sill.etalab.gouv.fr", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -21,5 +21,5 @@ "use strict"; | ||
}); | ||
await coreApi.functions.readWriteSillData.triggerPeriodicalNonIncrementalCompilation(); | ||
await coreApi.functions.readWriteSillData.manuallyTriggerNonIncrementalCompilation(); | ||
process.exit(0); | ||
})(); | ||
//# sourceMappingURL=trigger-compiled-data-branch-update.js.map |
@@ -27,3 +27,3 @@ import { assert } from "tsafe/assert"; | ||
console.log("start compiling"); | ||
console.log("Start compiling"); | ||
@@ -57,7 +57,2 @@ const { wikidataSoftwareBySillId, softwareLatestVersionBySillId } = await (async () => { | ||
: await getSoftwareLatestVersion({ "repoUrl": wikidataSoftware.sourceUrl }); | ||
console.log({ | ||
"sourceUrl": wikidataSoftware?.sourceUrl, | ||
"latestVersion": softwareLatestVersionBySillId[sillId] | ||
}); | ||
} | ||
@@ -69,3 +64,3 @@ } | ||
return softwareRows | ||
const compiledData = softwareRows | ||
.map(softwareRow => ({ | ||
@@ -137,2 +132,6 @@ softwareRow, | ||
); | ||
console.log("Done compiling"); | ||
return compiledData; | ||
}; | ||
@@ -139,0 +138,0 @@ |
@@ -14,3 +14,2 @@ import type { Db, WikidataEntry } from "./DbApi"; | ||
>; | ||
log?: typeof console.log; | ||
}) => Promise<CompiledData<"private">>; | ||
@@ -17,0 +16,0 @@ |
@@ -173,3 +173,3 @@ import structuredClone from "@ungap/structured-clone"; | ||
setInterval( | ||
() => dispatch(thunks.triggerPeriodicalNonIncrementalCompilation()), | ||
() => dispatch(localThunks.triggerNonIncrementalCompilation({ "triggerType": "periodical" })), | ||
4 * 3600 * 1000 //4 hour | ||
@@ -181,49 +181,8 @@ ); | ||
export const thunks = { | ||
"triggerPeriodicalNonIncrementalCompilation": | ||
"manuallyTriggerNonIncrementalCompilation": | ||
() => | ||
async (...args) => { | ||
const [dispatch, getState, extraArg] = args; | ||
const [dispatch] = args; | ||
const { dbApi, compileData } = extraArg; | ||
const { mutex } = getContext(extraArg); | ||
const dbBefore = structuredClone(getState()[name].db); | ||
console.log("here we go"); | ||
const newCompiledData = await compileData({ | ||
"db": dbBefore, | ||
"cache": {} | ||
}); | ||
console.log("after compilation"); | ||
const wasCanceled = await mutex.runExclusive(async (): Promise<boolean> => { | ||
const { db } = getState()[name]; | ||
if (!same(dbBefore, db)) { | ||
//While we where re compiling there was some other transaction, | ||
//Re-scheduling. | ||
return true; | ||
} | ||
await dbApi.updateCompiledData({ | ||
newCompiledData, | ||
"commitMessage": "Some Wikidata or other 3rd party source data have changed" | ||
}); | ||
dispatch( | ||
actions.updated({ | ||
db, | ||
"compiledData": newCompiledData | ||
}) | ||
); | ||
return false; | ||
}); | ||
if (wasCanceled) { | ||
await dispatch(thunks.triggerPeriodicalNonIncrementalCompilation()); | ||
} | ||
await dispatch(localThunks.triggerNonIncrementalCompilation({ "triggerType": "manual" })); | ||
}, | ||
@@ -712,2 +671,58 @@ "notifyPushOnMainBranch": | ||
}); | ||
}, | ||
"triggerNonIncrementalCompilation": | ||
(params: { triggerType: "periodical" | "manual" }) => | ||
async (...args) => { | ||
const { triggerType } = params; | ||
const [dispatch, getState, extraArg] = args; | ||
const { dbApi, compileData } = extraArg; | ||
const { mutex } = getContext(extraArg); | ||
const dbBefore = structuredClone(getState()[name].db); | ||
const newCompiledData = await compileData({ | ||
"db": dbBefore, | ||
"cache": {} | ||
}); | ||
const wasCanceled = await mutex.runExclusive(async (): Promise<boolean> => { | ||
const { db } = getState()[name]; | ||
if (!same(dbBefore, db)) { | ||
//While we where re compiling there was some other transaction, | ||
//Re-scheduling. | ||
console.log( | ||
"Re-scheduling non incremental compilation, db has changed (probably due to a concurrent transaction)" | ||
); | ||
return true; | ||
} | ||
await dbApi.updateCompiledData({ | ||
newCompiledData, | ||
"commitMessage": (() => { | ||
switch (triggerType) { | ||
case "periodical": | ||
return "Periodical update: Some Wikidata or other 3rd party source data have changed"; | ||
case "manual": | ||
return "Manual trigger: Some data have changed since last compilation"; | ||
} | ||
})() | ||
}); | ||
dispatch( | ||
actions.updated({ | ||
db, | ||
"compiledData": newCompiledData | ||
}) | ||
); | ||
return false; | ||
}); | ||
if (wasCanceled) { | ||
await dispatch(localThunks.triggerNonIncrementalCompilation(params)); | ||
} | ||
} | ||
@@ -714,0 +729,0 @@ } satisfies Thunks; |
@@ -27,5 +27,5 @@ import { createCoreApi } from "../core"; | ||
await coreApi.functions.readWriteSillData.triggerPeriodicalNonIncrementalCompilation(); | ||
await coreApi.functions.readWriteSillData.manuallyTriggerNonIncrementalCompilation(); | ||
process.exit(0); | ||
})(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
629264
12028