Skip to content

Commit

Permalink
Only run jobs in Prod (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbiang888 authored Dec 28, 2020
1 parent 4871c4f commit f9f09d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
17 changes: 7 additions & 10 deletions api/jobs/processors/cronNightlyEmailProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ import db from '../../models/db';
import { getConnection } from 'typeorm';
import { Campaign } from '../../models/entity/Campaign';
import { sendNightlyEmailQueue } from '../queues';
import { renderError } from '../helpers/addJobs';

export default (job: { data: any }, done: any): Promise<any> => {
return db().then(async () => {
export default async (job: { data: any }): Promise<any> => {
if (process.env.APP_ENV === 'production') {
await db();
const campaignRepository = getConnection('default').getRepository('Campaign');
const campaigns = await campaignRepository.find() as Campaign[];
const promises = [];
campaigns.forEach((campaign: Campaign): void => {
promises.push(sendNightlyEmailQueue.add({id: campaign.id}, {attempts: 1}));
});
return Promise.all(promises);
})
.then(() => done())
.catch(error => {
console.error(error);
renderError(error);
done();
});
} else {
console.log('Not sending job in staging.');
return;
}
};
19 changes: 8 additions & 11 deletions api/jobs/processors/dataScienceRetrieverProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { getGISCoordinates, retrieveAndSaveMatchResultAsync } from '../../services/contributionService';
import db from '../../models/db';
import { renderError } from '../helpers/addJobs';

export default (job: {data: any}, done: any): Promise<any> => {
return db().then(async () => {
export default async (job: {data: any}): Promise<any> => {
if (process.env.APP_ENV === 'production') {
await db();
await getGISCoordinates(job.data.id);
await retrieveAndSaveMatchResultAsync(job.data.id);
})
.then(() => done())
.catch(error => {
console.error(error);
renderError(error);
done();
});
return await retrieveAndSaveMatchResultAsync(job.data.id);
} else {
console.log('Not sending job in staging.');
return;
}
};
9 changes: 7 additions & 2 deletions api/jobs/processors/sendNightlyEmailProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import db from '../../models/db';
import { sendActivityEmailToCampaignAdminsAsync } from '../../services/emailService';

export default async (job: { data: any }): Promise<any> => {
await db();
return await sendActivityEmailToCampaignAdminsAsync(job.data.id);
if (process.env.APP_ENV === 'production') {
await db();
return await sendActivityEmailToCampaignAdminsAsync(job.data.id);
} else {
console.log('Not sending job in staging.');
return;
}
};

0 comments on commit f9f09d1

Please sign in to comment.