Skip to content

Commit

Permalink
feat(puppetter): Make new page timeout a config option
Browse files Browse the repository at this point in the history
feat(poller): Make poller enable a config option

Signed-off-by: Andrew Balmos <[email protected]>
  • Loading branch information
abalmos committed Oct 17, 2024
1 parent afa168f commit 568c631
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
16 changes: 16 additions & 0 deletions service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ export const { config } = await libConfig({
env: 'NODE_ENV',
arg: 'mode',
},
puppeteer: {
newPageTimeout: {
doc: 'How long (in milliseconds) to wait for a puppeteer new page to start up. This avoid some random hangs.',
format: Number,
default: 5000,
env: 'SERVICE_PUPPETEER_NEW_PAGE_TIMEOUT',
arg: 'service-puppeteer-new-page-timeout',
},
},
service: {
poller: {
enable: {
doc: 'Enable the poller service to find new work within Zendesk',
format: Boolean,
default: true,
env: 'SERVICE_POLLER_ENABLE',
arg: 'service-poller-enable',
},
pollRate: {
doc: 'Polling rate in seconds',
format: Number,
Expand Down
8 changes: 6 additions & 2 deletions service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ async function run() {
log.info('Start @oada/jobs based services');
await service.start();

log.info('Start polling ZenDesk polling service');
poller = pollerService(log, oada);
if (config.get('service.poller.enable')) {
log.info('Start polling ZenDesk polling service');
poller = pollerService(log, oada);
} else {
log.info('ZenDesk polling disabled.');
}
} catch (error) {
log.fatal({ error }, `Failed to start service: ${error}`);

Expand Down
8 changes: 6 additions & 2 deletions service/src/zd/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { config } from '../config.js';

import { type Logger } from '@oada/pino-debug';
import { access } from 'node:fs/promises';
import { createReadStream } from 'node:fs';
Expand Down Expand Up @@ -113,7 +115,7 @@ export async function generateTicketPdf(

try {
page = await pTimeout(browser.newPage(), {
milliseconds: 1000,
milliseconds: config.get('puppeteer.newPageTimeout'),
async fallback() {
log.debug('Could not start new page. Trying again.');

Expand All @@ -132,7 +134,9 @@ export async function generateTicketPdf(
dumpio: false,
});

return pTimeout(browser.newPage(), { milliseconds: 1000 });
return pTimeout(browser.newPage(), {
milliseconds: config.get('puppeteer.newPageTimeout'),
});
},
});
} catch (error) {
Expand Down

0 comments on commit 568c631

Please sign in to comment.