From 3a974c61d19a64671b33c3e93a764122abfa4979 Mon Sep 17 00:00:00 2001 From: MrClemRkz Date: Fri, 10 Jul 2020 12:04:17 +0530 Subject: [PATCH 1/3] update aligned json input for the template --- .../complaints/full_summary_report.md | 216 +++++++++--------- 1 file changed, 105 insertions(+), 111 deletions(-) diff --git a/templates/incidents/complaints/full_summary_report.md b/templates/incidents/complaints/full_summary_report.md index 35adeab..333a25a 100644 --- a/templates/incidents/complaints/full_summary_report.md +++ b/templates/incidents/complaints/full_summary_report.md @@ -4,138 +4,132 @@ Use the following JSON as request body to populate report. ```JSON { - "file": { - "template": "incidents/complaints/daily_summary_report.js", - "incidents": [ - { - "refId": "EC/EDR/PE20/JAF/0002", - "channel": "Letter", - "created_date": "2020/06/15", - "reporter": "adasdasdad", - "location": "fsdfdfdsf - Jaffna", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/JAF/0003", - "channel": "Email", - "created_date": "2020/06/15", - "reporter": "sdfasdfd", - "location": "Jaffna", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/JAF/0003", - "channel": "Letter", - "created_date": "2020/06/15", - "reporter": "asdfsdf", - "location": "Jaffna", - "summery" : "shkdfksjdhf kjshdfk" + "margin.top": "15", + "margin.right": "1", + "margin.bottom": "0.5", + "margin.left": "1.5", + "format": "A3", + "landscape": true, + "file": { + "template": "incidents/complaints/full_summary_report.js", + "date": "2020/07/10", + "dateInfo": "2020/07/09 4:00pm - 2020/07/10 4:00pm", + "complaints": [ + { + "complaintNo": "EC/EDR/PE20/KAN/0009", + "channelLtr": "x", + "channelTel": "", + "channelFax": "", + "channelMail": "", + "complaintDate": "2020/06/09", + "reporter": "", + "location": "Kandy", + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.", + "violentAction": "A-4", + "violationOfElectionLaw": "", + "other": "", + "law": "", + "medium": "x", + "critical": "", + "reportedParty": "-", + "progress": "-" }, { - "refId": "EC/EDR/PE20/HAM/0004", - "channel": "Letter", - "created_date": "2020/06/21", + "complaintNo": "EC/EDR/PE20/HAM/0004", + "channelLtr": "x", + "channelTel": "", + "channelFax": "", + "channelMail": "", + "complaintDate": "2020/06/21", "reporter": "Cleement", "location": "Hambantota", - "summery" : "shkdfksjdhf kjshdfk" + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.", + "violentAction": "", + "violationOfElectionLaw": "B-13", + "other": "", + "law": "", + "medium": "", + "critical": "x", + "reportedParty": "-", + "progress": "-" }, { - "refId": "EC/EDR/PE20/GAM/0005", - "channel": "Email", - "created_date": "2020/06/22", + "complaintNo": "EC/EDR/PE20/GAM/0005", + "channelLtr": "", + "channelTel": "", + "channelFax": "", + "channelMail": "x", + "complaintDate": "2020/06/22", "reporter": "adadadadadass", "location": "Gampaha", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/KAN/0006", - "channel": "Email", - "created_date": "2020/06/25", - "reporter": "", - "location": "Kandy", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/GAM/0007", - "channel": "Letter", - "created_date": "2020/06/25", - "reporter": "", - "location": "Gampaha", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/GAM/0008", - "channel": "Fax", - "created_date": "2020/06/25", - "reporter": "", - "location": "Gampaha", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/KAN/0009", - "channel": "Letter", - "created_date": "2020/06/25", - "reporter": "", - "location": "Kandy", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/GAM/0010", - "channel": "Letter", - "created_date": "2020/06/26", - "reporter": "", - "location": "Gampaha", - "summery" : "shkdfksjdhf kjshdfk" + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.", + "violentAction": "", + "violationOfElectionLaw": "B-13", + "other": "", + "law": "", + "medium": "x", + "critical": "", + "reportedParty": "-", + "progress": "-" }, { - "refId": "EC/EDR/PE20/JAF/0011", - "channel": "Letter", - "created_date": "2020/06/26", + "complaintNo": "EC/EDR/PE20/JAF/0011", + "channelLtr": "x", + "channelTel": "", + "channelFax": "", + "channelMail": "", + "complaintDate": "2020/06/26", "reporter": "", "location": "Jaffna", - "summery" : "shkdfksjdhf kjshdfk" + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.", + "violentAction": "", + "violationOfElectionLaw": "", + "other": "Other", + "law": "", + "medium": "", + "critical": "x", + "reportedParty": "Education Department ", + "progress": " situation is handled." }, { - "refId": "EC/EDR/PE20/HAM/0014", - "channel": "Letter", - "created_date": "2020/07/01", - "reporter": "sfsdfdfdf", - "location": "Hambantota", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/KEG/0012", - "channel": "Letter", - "created_date": "2020/07/01", - "reporter": "sdfafasdf", - "location": "Kegalle", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/JAF/0013", - "channel": "Letter", - "created_date": "2020/07/01", + "complaintNo": "EC/EDR/PE20/JAF/0013", + "channelLtr": "x", + "channelTel": "", + "channelFax": "", + "channelMail": "", + "complaintDate": "2020/07/01", "reporter": "", "location": "Jaffna", - "summery" : "shkdfksjdhf kjshdfk" + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.", + "violentAction": "A-8", + "violationOfElectionLaw": "", + "other": "", + "law": "x", + "medium": "", + "critical": "", + "reportedParty": "-", + "progress": "-" }, { - "refId": "EC/EDR/PE20/KIL/0015", - "channel": "Letter", - "created_date": "2020/07/01", + "complaintNo": "EC/EDR/PE20/KIL/0015", + "channelLtr": "x", + "channelTel": "", + "channelFax": "", + "channelMail": "", + "complaintDate": "2020/07/01", "reporter": "asdfasdf", "location": "Kilinochchi", - "summery" : "shkdfksjdhf kjshdfk" - }, - { - "refId": "EC/EDR/PE20/GAM/0016", - "channel": "Letter", - "created_date": "2020/07/01", - "reporter": "", - "location": "Gampaha", - "summery" : "shkdfksjdhf kjshdfk" + "complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.", + "violentAction": "", + "violationOfElectionLaw": "B-23", + "other": "", + "law": "", + "medium": "x", + "critical": "", + "reportedParty": "Legal Department ", + "progress": " Proper way is to manage outcome." } ] - } + } } ``` From 67108152c5919721f57cab80b4aab1a82446d543 Mon Sep 17 00:00:00 2001 From: MrClemRkz Date: Fri, 31 Jul 2020 15:13:25 +0530 Subject: [PATCH 2/3] fix on headless engine crash issue --- .gitignore | 3 ++- handlers/generate.js | 24 ++++++++++++++++++++++-- puppeteer.js | 2 +- purge_expired.js | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4c633a5..41c866e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ config.json .DS_Store package-lock.json static/exports -.env \ No newline at end of file +.env +report.* \ No newline at end of file diff --git a/handlers/generate.js b/handlers/generate.js index 72968ef..39a03a7 100644 --- a/handlers/generate.js +++ b/handlers/generate.js @@ -47,9 +47,9 @@ module.exports = async function(req, res) { } if (!global.browser) { - const browser = await puppeteer.launch({ args: ['--no-sandbox'] }) + await reGenerateBrowser(); } - const page = await global.browser.newPage(); + const page = await getNewPageFromBrowser(); page.setDefaultNavigationTimeout(0); if (req.body.url) { await page.goto(req.body.url); @@ -72,6 +72,26 @@ module.exports = async function(req, res) { }); } +async function getNewPageFromBrowser() { + const newPage = await global.browser.newPage().catch( (e) => { + console.log("Chrome engine එක පොඩ්ඩක් crash වෙලා මචන්.") + }) + + if (newPage) { + return newPage; + } else { + await reGenerateBrowser(); + console.log("Created a new page object."); + return await global.browser.newPage() + } + +} + +async function reGenerateBrowser() { + global.browser = await puppeteer.launch({ args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }); + console.log('Browser object regenerated.') +} + function revisedRandId() { return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10); } diff --git a/puppeteer.js b/puppeteer.js index dd369bc..861ba41 100644 --- a/puppeteer.js +++ b/puppeteer.js @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer'); const config = require('./config'); const headlessState = true; -puppeteer.launch({ headless: headlessState, args: ['--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) { +puppeteer.launch({ headless: headlessState, args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) { global.browser = browser; console.log('browser ready'); }); diff --git a/purge_expired.js b/purge_expired.js index c9704d8..9c4a3a5 100644 --- a/purge_expired.js +++ b/purge_expired.js @@ -28,4 +28,4 @@ function purgeExpired() { } } }); -} \ No newline at end of file +} From 649fa6cb6dc95ba7d4925fd237a6a681cca50f39 Mon Sep 17 00:00:00 2001 From: MrClemRkz Date: Fri, 31 Jul 2020 15:38:48 +0530 Subject: [PATCH 3/3] fix on browser instance crash issue --- .gitignore | 3 ++- handlers/generate.js | 24 ++++++++++++++++++++++-- puppeteer.js | 2 +- purge_expired.js | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4c633a5..41c866e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ config.json .DS_Store package-lock.json static/exports -.env \ No newline at end of file +.env +report.* \ No newline at end of file diff --git a/handlers/generate.js b/handlers/generate.js index 72968ef..2939f9b 100644 --- a/handlers/generate.js +++ b/handlers/generate.js @@ -47,9 +47,9 @@ module.exports = async function(req, res) { } if (!global.browser) { - const browser = await puppeteer.launch({ args: ['--no-sandbox'] }) + await reGenerateBrowser(); } - const page = await global.browser.newPage(); + const page = await getNewPageFromBrowser(); page.setDefaultNavigationTimeout(0); if (req.body.url) { await page.goto(req.body.url); @@ -72,6 +72,26 @@ module.exports = async function(req, res) { }); } +async function getNewPageFromBrowser() { + const newPage = await global.browser.newPage().catch( (e) => { + console.log("Browser instance seems to be dead.") + }) + + if (newPage) { + return newPage; + } else { + await reGenerateBrowser(); + console.log("Created a new page instance."); + return await global.browser.newPage() + } + +} + +async function reGenerateBrowser() { + global.browser = await puppeteer.launch({ args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }); + console.log('Browser instance regenerated.') +} + function revisedRandId() { return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10); } diff --git a/puppeteer.js b/puppeteer.js index dd369bc..861ba41 100644 --- a/puppeteer.js +++ b/puppeteer.js @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer'); const config = require('./config'); const headlessState = true; -puppeteer.launch({ headless: headlessState, args: ['--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) { +puppeteer.launch({ headless: headlessState, args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) { global.browser = browser; console.log('browser ready'); }); diff --git a/purge_expired.js b/purge_expired.js index c9704d8..9c4a3a5 100644 --- a/purge_expired.js +++ b/purge_expired.js @@ -28,4 +28,4 @@ function purgeExpired() { } } }); -} \ No newline at end of file +}