-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task #215480: [BE] Add org_id in Camp and update using group_users member_type and status active using user_id Task #215497 [BE] Add org_id in program_beneficaires and update org_id using facilitator_id by joining program_facilitator. user_id #904
base: release-2.8.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export class FaAttendanceProcessingCron { | |
} | ||
|
||
//3rd cron runs for each hour's 25th minute eg: 10:25am, 11::25am | ||
@Cron('25 * * * *') | ||
// @Cron('25 * * * *') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo |
||
async markAttendanceCron() { | ||
try { | ||
/*----------------------- Mark attendance of from face index of users in collection -----------------------*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export class FaFaceIndexingCron { | |
} | ||
|
||
//2nd cron runs for each hour's 15th minute eg: 10:15am, 11::15am | ||
@Cron('15 * * * *') | ||
// @Cron('15 * * * *') | ||
manojLondhe marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo |
||
async indexRekognitionUsers() { | ||
try { | ||
/*----------------------- Create face index of users in collection -----------------------*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ export class FaUserIndexingCron { | |
} | ||
|
||
//first cron runs for each hour's 5th minute eg: 10:05am, 11::05am | ||
@Cron('05 * * * *') | ||
// @Cron('05 * * * *') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo |
||
async createCollectionUsers() { | ||
try { | ||
/*----------------------- Create users in collection -----------------------*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Cron } from '@nestjs/schedule'; | ||
import { HasuraService } from '../services/hasura/hasura.service'; | ||
|
||
@Injectable() | ||
export class HousekeepingCron { | ||
constructor(private hasuraService: HasuraService) {} | ||
|
||
// Cronjob runs every day at 12am | ||
// @Cron('0/1 * * * *') | ||
async updateCamp() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. give it better name |
||
// Get today's date | ||
const column_create_or_exists = await this.addColumn({ | ||
table_name: 'groups', | ||
column_name: 'org_id', | ||
}); | ||
console.log(column_create_or_exists); | ||
if (column_create_or_exists?.exist) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see if we can use transaction start end? |
||
const updateQuery = `UPDATE groups AS g | ||
SET org_id = pf.parent_ip | ||
FROM ( | ||
SELECT g.id, g.program_id, g.academic_year_id, gu.user_id, gu.member_type, gu.status | ||
FROM groups AS g | ||
JOIN group_users AS gu ON g.id = gu.group_id | ||
WHERE gu.member_type = 'owner' AND gu.status = 'active' | ||
) AS sub | ||
JOIN program_faciltators AS pf ON sub.user_id = pf.user_id | ||
AND sub.program_id = pf.program_id | ||
AND sub.academic_year_id = pf.academic_year_id | ||
WHERE g.id = sub.id;`; | ||
manojLondhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const result1 = await this.hasuraService.executeRawSql(updateQuery); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use try catch, push to Sentry in case of failure |
||
console.log('update org_id in groups', result1); | ||
} | ||
return true; | ||
manojLondhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// @Cron('0/1 * * * *') | ||
async updateLeaner() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. give this better name |
||
// Get today's date | ||
const column_create_or_exists = await this.addColumn({ | ||
table_name: 'program_beneficiaries', | ||
column_name: 'org_id', | ||
}); | ||
if (column_create_or_exists?.exist) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use try catch, push to Sentry in case of failure |
||
const updateQuery = `UPDATE program_beneficiaries AS pb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see if we can use transaction start, end? |
||
SET org_id = pf.parent_ip | ||
FROM program_faciltators AS pf | ||
WHERE pb.facilitator_id = pf.user_id | ||
AND pb.program_id = pf.program_id | ||
AND pb.academic_year_id = pf.academic_year_id;`; | ||
|
||
const result1 = await this.hasuraService.executeRawSql(updateQuery); | ||
console.log('update org_id in program_beneficiaries', result1); | ||
} | ||
return true; | ||
} | ||
|
||
async addColumn({ table_name, column_name }) { | ||
const r = await this.checkColumn({ | ||
table_name, | ||
column_name, | ||
}); | ||
if (r === 0) { | ||
const sql = `ALTER TABLE ${table_name} ADD COLUMN ${column_name} TEXT`; | ||
const sqlResult = await this.hasuraService.executeRawSql(sql); | ||
console.log(sql); | ||
return sqlResult; | ||
} | ||
return { exist: true }; | ||
} | ||
|
||
async checkColumn({ table_name, column_name }) { | ||
const sql = `SELECT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = '${table_name}' | ||
AND column_name = '${column_name}' | ||
) AS column_exists`; | ||
const sqlResult = await this.hasuraService.executeRawSql(sql); | ||
const datar = sqlResult?.result?.filter((e) => e.includes('t')).length; | ||
return datar; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ export class PrepareCertificateHtmlCron { | |
) {} | ||
|
||
//cron issue certificate run every 5 minutes | ||
@Cron(CronExpression.EVERY_5_MINUTES) | ||
// @Cron(CronExpression.EVERY_5_MINUTES) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undo |
||
async prepareCertificateHtml() { | ||
console.log('cron job: issueCertificate started at time ' + new Date()); | ||
//fetch all test tracking data which has certificate_status null | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this and in other crons