mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
[history-v1] use POST requests for expiring redis buffer from cron (#26568)
* [history-v1] use POST requests for expiring redis buffer from cron (cherry picked from commit 15780ac54e36b96e1aed9fd9eb6dfe9d4fbf842f) * [history-v1] remove double claim of expire job GitOrigin-RevId: 8b2eab07006a5819a47eed3f646b2a4d75f86e5b
This commit is contained in:
@@ -3,23 +3,48 @@ const commandLineArgs = require('command-line-args')
|
||||
const redis = require('../lib/redis')
|
||||
const { scanAndProcessDueItems } = require('../lib/scan')
|
||||
const { expireProject, claimExpireJob } = require('../lib/chunk_store/redis')
|
||||
const config = require('config')
|
||||
const { fetchNothing } = require('@overleaf/fetch-utils')
|
||||
|
||||
const rclient = redis.rclientHistory
|
||||
|
||||
const optionDefinitions = [{ name: 'dry-run', alias: 'd', type: Boolean }]
|
||||
const optionDefinitions = [
|
||||
{ name: 'dry-run', alias: 'd', type: Boolean },
|
||||
{ name: 'post-request', type: Boolean },
|
||||
]
|
||||
const options = commandLineArgs(optionDefinitions)
|
||||
const DRY_RUN = options['dry-run'] || false
|
||||
const POST_REQUEST = options['post-request'] || false
|
||||
const HISTORY_V1_URL = `http://${process.env.HISTORY_V1_HOST || 'localhost'}:${process.env.PORT || 3100}`
|
||||
|
||||
logger.initialize('expire-redis-chunks')
|
||||
|
||||
async function expireProjectAction(projectId) {
|
||||
const job = await claimExpireJob(projectId)
|
||||
await expireProject(projectId)
|
||||
if (POST_REQUEST) {
|
||||
await requestProjectExpiry(projectId)
|
||||
} else {
|
||||
await expireProject(projectId)
|
||||
}
|
||||
if (job && job.close) {
|
||||
await job.close()
|
||||
}
|
||||
}
|
||||
|
||||
async function requestProjectExpiry(projectId) {
|
||||
logger.debug({ projectId }, 'sending project expire request')
|
||||
const url = `${HISTORY_V1_URL}/api/projects/${projectId}/expire`
|
||||
const credentials = Buffer.from(
|
||||
`staging:${config.get('basicHttpAuth.password')}`
|
||||
).toString('base64')
|
||||
await fetchNothing(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Basic ${credentials}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function runExpireChunks() {
|
||||
await scanAndProcessDueItems(
|
||||
rclient,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
node storage/scripts/persist_redis_chunks.mjs --queue --max-time 270
|
||||
node storage/scripts/expire_redis_chunks.js
|
||||
node storage/scripts/expire_redis_chunks.js --post-request
|
||||
|
||||
Reference in New Issue
Block a user