|
14 | 14 | const { sequelize } = require('../../../database/index.js'); |
15 | 15 | const { utilities: { TransactionHelper } } = require('../../../database'); |
16 | 16 | const { EnvironmentHistoryItemRepository } = require('../../../database/repositories/index.js'); |
| 17 | +const { timestampToMysql } = require('../../utilities/timestampToMysql.js'); |
17 | 18 |
|
18 | 19 | /** |
19 | 20 | * Consider all the environments that are currently active but not in the given list of ids to be lost, and transition them to error |
20 | 21 | * |
21 | 22 | * @param {string[]} activeEnvironmentIds the ids of active environments (those environments will not be transitioned to error) |
22 | | - * @param {number} modificationTimeWindow the time we have (in MINUTES), after the creation of an environment, to purge them. If an environment |
23 | | - * has been created more than this amount of minutes before NOW, it is NOT purged |
| 23 | + * @param {Period} modificationTimePeriod environments created outside this time period will not be updated |
24 | 24 | * @return {Promise<number[]>} resolve once all inactive environments has been transitioned to error with their ids |
25 | 25 | * @deprecated |
26 | 26 | */ |
27 | | -exports.transitionToErrorLostEnvironments = async (activeEnvironmentIds, modificationTimeWindow) => { |
| 27 | +exports.transitionToErrorLostEnvironments = async (activeEnvironmentIds, modificationTimePeriod) => { |
28 | 28 | // The select query is adapted for the insert |
29 | 29 | let selectQuery = ` |
30 | 30 | SELECT e.id |
31 | 31 | FROM environments_history_items ehi |
32 | 32 | INNER JOIN environments e ON ehi.environment_id = e.id |
33 | | - GROUP BY e.id, e.updated_at |
34 | | - HAVING e.updated_at > date_sub(now(), INTERVAL ${modificationTimeWindow} MINUTE) |
| 33 | + GROUP BY e.id, e.updated_at, e.created_at |
| 34 | + HAVING e.updated_at >= '${timestampToMysql(modificationTimePeriod.from)}' |
| 35 | + AND e.created_at < '${timestampToMysql(modificationTimePeriod.to)}' |
35 | 36 | AND group_concat(ehi.status) NOT LIKE '%ERROR%' |
36 | 37 | AND group_concat(ehi.status) NOT LIKE '%DESTROYED%' |
37 | 38 | `; |
|
0 commit comments