Skip to content

Commit

Permalink
fix: pollDb and mail report
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Aug 22, 2024
1 parent 4b1ec20 commit 0ccaa32
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { validateEmail } from 'validations-br';
/**
* Enum CronJobServicesJobs
*/
export enum CrobJobsEnum {
export enum CronJobsEnum {
bulkSendInvites = 'bulkSendInvites',
sendStatusReport = 'sendStatusReport',
sendStatusReportTemp = 'sendStatusReportTemp',
Expand All @@ -50,7 +50,7 @@ interface ICronJob {

interface ICronJobSetting {
setting: ISettingData;
cronJob: CrobJobsEnum;
cronJob: CronJobsEnum;
isEnabledFlag?: ISettingData;
}

Expand All @@ -76,22 +76,31 @@ export class CronJobsService {

this.jobsConfig.push(
{
name: CrobJobsEnum.bulkSendInvites,
/** NÃO REMOVER ESTE JOB, É ÚTIL PARA ALTERAR OS CRONJOBS EM CASO DE URGÊNCIA */
name: CronJobsEnum.pollDb,
cronJobParameters: {
// cronjob: * * * * - A cada minuto
cronTime: (await this.settingsService.getOneBySettingData(appSettings.any__poll_db_cronjob, true, THIS_CLASS_WITH_METHOD)).getValueAsString(),
onTick: async () => this.pollDb(),
},
},
{
name: CronJobsEnum.bulkSendInvites,
cronJobParameters: {
cronTime: (await this.settingsService.getOneBySettingData(appSettings.any__mail_invite_cronjob, true, THIS_CLASS_WITH_METHOD)).getValueAsString(),
onTick: async () => this.bulkSendInvites(),
},
},
/** NÃO DESABILITAR ENVIO DE REPORT */
{
name: CrobJobsEnum.sendStatusReport,
/** NÃO DESABILITAR ENVIO DE REPORT */
name: CronJobsEnum.sendStatusReport,
cronJobParameters: {
cronTime: (await this.settingsService.getOneBySettingData(appSettings.any__mail_report_cronjob, true, THIS_CLASS_WITH_METHOD)).getValueAsString(),
onTick: () => this.sendStatusReport(),
},
},
{
name: CrobJobsEnum.bulkResendInvites,
name: CronJobsEnum.bulkResendInvites,
cronJobParameters: {
cronTime: '45 14 15 * *', // Day 15, 14:45 GMT = 11:45 BRT (GMT-3)
onTick: async () => {
Expand All @@ -100,7 +109,7 @@ export class CronJobsService {
},
},
{
name: CrobJobsEnum.updateTransacaoViewVan,
name: CronJobsEnum.updateTransacaoViewVan,
cronJobParameters: {
cronTime: '*/30 * * * *', // Every 30 min
onTick: async () => {
Expand All @@ -109,7 +118,7 @@ export class CronJobsService {
},
},
{
name: CrobJobsEnum.updateTransacaoViewEmpresa,
name: CronJobsEnum.updateTransacaoViewEmpresa,
cronJobParameters: {
cronTime: '0 9 * * *', // Every day, 06:00 GMT = 09:00 BRT (GMT-3)
onTick: async () => {
Expand All @@ -118,7 +127,7 @@ export class CronJobsService {
},
},
{
name: CrobJobsEnum.updateTransacaoViewVLT,
name: CronJobsEnum.updateTransacaoViewVLT,
cronJobParameters: {
cronTime: '0 9 * * *', // Every day, 06:00 GMT = 09:00 BRT (GMT-3)
onTick: async () => {
Expand All @@ -127,7 +136,7 @@ export class CronJobsService {
},
},
{
name: CrobJobsEnum.syncTransacaoViewOrdemPgto,
name: CronJobsEnum.syncTransacaoViewOrdemPgto,
cronJobParameters: {
cronTime: '0 9 * * *', // Every day, 06:00 GMT = 09:00 BRT (GMT-3)
onTick: async () => {
Expand All @@ -136,7 +145,7 @@ export class CronJobsService {
},
},
{
name: CrobJobsEnum.updateRetorno,
name: CronJobsEnum.updateRetorno,
cronJobParameters: {
cronTime: '*/30 * * * *', // Every 30 min
onTick: async () => {
Expand Down Expand Up @@ -559,7 +568,6 @@ export class CronJobsService {
return;
}
if (!settingPollDbActive.getValueAsBoolean()) {
this.logger.log(`Tarefa cancelada pois setting.${appSettings.any__poll_db_enabled.name}' = 'false'` + ` Para ativar, altere na tabela 'setting'`, METHOD);
return;
}

Expand All @@ -568,15 +576,15 @@ export class CronJobsService {
const cronjobSettings: ICronJobSetting[] = [
{
setting: appSettings.any__poll_db_cronjob,
cronJob: CrobJobsEnum.pollDb,
cronJob: CronJobsEnum.pollDb,
},
{
setting: appSettings.any__mail_invite_cronjob,
cronJob: CrobJobsEnum.bulkSendInvites,
cronJob: CronJobsEnum.bulkSendInvites,
},
{
setting: appSettings.any__mail_report_cronjob,
cronJob: CrobJobsEnum.sendStatusReport,
cronJob: CronJobsEnum.sendStatusReport,
},
];
for (const setting of cronjobSettings) {
Expand All @@ -585,12 +593,6 @@ export class CronJobsService {
hasDbChanges = true;
}
}

if (hasDbChanges) {
this.logger.log('Tarefa finalizada.', METHOD);
} else {
this.logger.log('Tarefa finalizada, sem alterações no banco.', METHOD);
}
}

async handleCronjobSettings(args: ICronJobSetting, thisMethod: string): Promise<boolean> {
Expand Down

0 comments on commit 0ccaa32

Please sign in to comment.