mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 19:04:38 +00:00
use date-fns + rename variables
This commit is contained in:
parent
3741876099
commit
3d231fb376
@ -64,7 +64,7 @@
|
||||
"codemirror": "^5.65.6",
|
||||
"cross-env": "^7.0.3",
|
||||
"css-loader": "6.7.1",
|
||||
"date-fns": "2.28.0",
|
||||
"date-fns": "2.29.1",
|
||||
"dotenv": "8.5.1",
|
||||
"esbuild-loader": "^2.19.0",
|
||||
"execa": "^1.0.0",
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
"test:unit": "jest --verbose"
|
||||
},
|
||||
"dependencies": {
|
||||
"date-fns": "2.28.0",
|
||||
"date-fns": "2.29.1",
|
||||
"debug": "4.3.1",
|
||||
"fs-extra": "10.0.0",
|
||||
"knex": "1.0.4",
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
"@strapi/icons": "1.2.0",
|
||||
"babel-loader": "^8.2.5",
|
||||
"cross-env": "^7.0.3",
|
||||
"date-fns": "2.28.0",
|
||||
"date-fns": "2.29.1",
|
||||
"rimraf": "3.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
"@strapi/utils": "4.2.2",
|
||||
"byte-size": "7.0.1",
|
||||
"cropperjs": "1.5.12",
|
||||
"date-fns": "2.29.1",
|
||||
"fs-extra": "10.0.0",
|
||||
"immer": "9.0.6",
|
||||
"koa-range": "0.3.0",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { defaultTo } = require('lodash/fp');
|
||||
const { add } = require('date-fns');
|
||||
const { FOLDER_MODEL_UID, FILE_MODEL_UID } = require('../constants');
|
||||
const { getWeeklyCronScheduleAt } = require('../utils/cron');
|
||||
|
||||
@ -13,12 +14,6 @@ const getMetricsStoreValue = async () => {
|
||||
const setMetricsStoreValue = value =>
|
||||
strapi.store.set({ type: 'plugin', name: 'upload', key: 'metrics', value });
|
||||
|
||||
const addMinutes = (date, offset) => {
|
||||
const newDate = new Date(date);
|
||||
newDate.setMinutes(newDate.getMinutes() + offset);
|
||||
return newDate;
|
||||
};
|
||||
|
||||
module.exports = ({ strapi }) => ({
|
||||
async computeMetrics() {
|
||||
// Folder metrics
|
||||
@ -100,27 +95,27 @@ module.exports = ({ strapi }) => ({
|
||||
strapi.telemetry.send('didSendUploadPropertiesOnceAWeek', metrics);
|
||||
|
||||
const metricsInfoStored = await getMetricsStoreValue();
|
||||
await setMetricsStoreValue({ ...metricsInfoStored, lastMetricsUpdate: new Date().getTime() });
|
||||
await setMetricsStoreValue({ ...metricsInfoStored, lastWeeklyUpdate: new Date().getTime() });
|
||||
},
|
||||
|
||||
async ensureWeeklyStoredCronSchedule() {
|
||||
const metricsInfoStored = await getMetricsStoreValue();
|
||||
const { cronSchedule: currCronSchedule, lastMetricsUpdate } = metricsInfoStored;
|
||||
const { weeklySchedule: currentSchedule, lastWeeklyUpdate } = metricsInfoStored;
|
||||
|
||||
const now = new Date();
|
||||
let cronSchedule = currCronSchedule;
|
||||
let weeklySchedule = currentSchedule;
|
||||
|
||||
if (!currCronSchedule || !lastMetricsUpdate || lastMetricsUpdate + ONE_WEEK < now.getTime()) {
|
||||
cronSchedule = getWeeklyCronScheduleAt(addMinutes(now, 5));
|
||||
await setMetricsStoreValue({ ...metricsInfoStored, cronSchedule });
|
||||
if (!currentSchedule || !lastWeeklyUpdate || lastWeeklyUpdate + ONE_WEEK < now.getTime()) {
|
||||
weeklySchedule = getWeeklyCronScheduleAt(add(now, { minutes: 5 }));
|
||||
await setMetricsStoreValue({ ...metricsInfoStored, weeklySchedule });
|
||||
}
|
||||
|
||||
return cronSchedule;
|
||||
return weeklySchedule;
|
||||
},
|
||||
|
||||
async registerCron() {
|
||||
const cronSchedule = await this.ensureWeeklyStoredCronSchedule();
|
||||
const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
|
||||
|
||||
strapi.cron.add({ [cronSchedule]: this.sendMetrics.bind(this) });
|
||||
strapi.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
|
||||
},
|
||||
});
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sindresorhus/slugify": "1.1.0",
|
||||
"date-fns": "2.28.0",
|
||||
"date-fns": "2.29.1",
|
||||
"http-errors": "1.8.1",
|
||||
"lodash": "4.17.21",
|
||||
"yup": "0.32.9"
|
||||
|
||||
@ -10757,10 +10757,10 @@ date-and-time@^0.6.3:
|
||||
resolved "https://registry.yarnpkg.com/date-and-time/-/date-and-time-0.6.3.tgz#2daee52df67c28bd93bce862756ac86b68cf4237"
|
||||
integrity sha512-lcWy3AXDRJOD7MplwZMmNSRM//kZtJaLz4n6D1P5z9wEmZGBKhJRBIr1Xs9KNQJmdXPblvgffynYji4iylUTcA==
|
||||
|
||||
date-fns@2.28.0:
|
||||
version "2.28.0"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.28.0.tgz#9570d656f5fc13143e50c975a3b6bbeb46cd08b2"
|
||||
integrity sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==
|
||||
date-fns@2.29.1:
|
||||
version "2.29.1"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.1.tgz#9667c2615525e552b5135a3116b95b1961456e60"
|
||||
integrity sha512-dlLD5rKaKxpFdnjrs+5azHDFOPEu4ANy/LTh04A1DTzMM7qoajmKCBc8pkKRFT41CNzw+4gQh79X5C+Jq27HAw==
|
||||
|
||||
dateformat@^3.0.0:
|
||||
version "3.0.3"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user