resumeCampaign resets semana_iniciada_em to avoid immediate escalation
resumeCampaign only updated status/pause_reason, so a campaign auto-paused
for many days and then resumed could immediately satisfy
escalateWeeklyLimits' 7-day check and double its daily limit right after
coming back from an unhealthy state -- the opposite of the intended
safety behavior. Now resumeCampaign also stamps semana_iniciada_em to
datetime('now'), resetting the weekly clock on every resume.
This commit is contained in:
@@ -79,6 +79,23 @@ test('setCampaignStatus rodando does not reset already-set semana_iniciada_em',
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('resumeCampaign reseta semana_iniciada_em, evitando escalonamento imediato apos retomar de uma pausa longa', () => {
|
||||
const db = openDb(':memory:');
|
||||
const campanha = createCampaign(db, campanhaBase({ limiteDiarioInicial: 10, limiteDiarioTeto: 80 }));
|
||||
setCampaignStatus(db, campanha.id, 'rodando');
|
||||
setCampaignStatus(db, campanha.id, 'pausado', 'high_failure_rate');
|
||||
// Simula que a campanha ficou pausada por muito tempo: semana_iniciada_em
|
||||
// backdated 10 dias, o que satisfaria os "7 dias corridos" do escalonamento.
|
||||
db.prepare(`UPDATE outreach_campaigns SET semana_iniciada_em = datetime('now', '-10 days') WHERE id = ?`).run(campanha.id);
|
||||
|
||||
resumeCampaign(db, campanha.id);
|
||||
const escaladas = escalateWeeklyLimits(db);
|
||||
assert.equal(escaladas, 0, 'retomar deveria ter resetado o relogio semanal, entao nao deveria escalonar imediatamente');
|
||||
const atualizada = getCampaign(db, campanha.id);
|
||||
assert.equal(atualizada.limite_diario_atual, 10);
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('resumeCampaign nao faz nada se a campanha nao estiver pausada', () => {
|
||||
const db = openDb(':memory:');
|
||||
const campanha = createCampaign(db, campanhaBase());
|
||||
|
||||
Reference in New Issue
Block a user