Skip to content

Commit

Permalink
Support export particular PM jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhina-e committed Sep 29, 2024
1 parent 853184d commit fefdc7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jobs/arbimon-recording-export-job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function main () {
return new Promise((resolve, reject) => {
const exportReportType = 'Pattern Matchings';
console.log(`Arbimon Export ${exportReportType} job`)
patternMatching.collectData(filters, async (err, filePath) => {
patternMatching.collectData(filters, projection_parameters, async (err, filePath) => {
const reportName = 'pattern-matching-export'
const zipPath = `jobs/arbimon-recording-export-job/${reportName}.zip`
const bucketFormatted = S3_EXPORT_BUCKET_ARBIMON.split('/')[0]
Expand Down
8 changes: 4 additions & 4 deletions jobs/arbimon-recording-export-job/pattern-matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const tmpFilePath = __dirname + '/tmpfilecache'
const archive = archiver('zip', { zlib: { level: 9 }});
let outputStreamFile

async function collectData (filters, cb) {
async function collectData (filters, projection_parameters, cb) {
outputStreamFile = fs.createWriteStream(__dirname + '/pattern-matching-export.zip');

archive.pipe(outputStreamFile)
await exportAllPmJobs(filters.project_id, async (err, data) => {
await exportAllPmJobs(filters.project_id, projection_parameters, async (err, data) => {
if (err) {
console.err('Error export PM', err)
return cb(err)
Expand Down Expand Up @@ -63,11 +63,11 @@ async function fileToZipDirectory (sourceFilePath, sourceFileName) {
});
}

async function exportAllPmJobs (projectId, cb) {
async function exportAllPmJobs (projectId, projection_parameters, cb) {
try {
console.log(`${exportReportJob} started`)
const projectSites = await getProjectSites({projectId})
const projectPMJobs = await getProjectPMJobs({projectId})
const projectPMJobs = await getProjectPMJobs({projectId, jobs: projection_parameters.pm})
await exportAllPmJobsCsv(projectPMJobs)
for (let job of projectPMJobs) {
const fileName = `${nameToUrl(job.job_name)}_${job.job_id}.csv`;
Expand Down
3 changes: 3 additions & 0 deletions jobs/services/pattern-matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ async function getProjectPMJobs (options = {}) {
where pm.project_id = ${options.projectId} and pm.deleted = 0 and j.state = 'completed'
;
`
if (options.jobs && options.jobs.length > 0) {
sql += `and pm.pattern_matching_id in (${options.jobs})`
}
const [rows, fields] = await connection.execute(sql)
return rows
}
Expand Down

0 comments on commit fefdc7f

Please sign in to comment.