Skip to content

Commit

Permalink
feat(script): Script to re-process closed tickets by ID range
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Balmos <[email protected]>
  • Loading branch information
abalmos committed Nov 6, 2024
1 parent 50c13ed commit e029b0d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "tsc -b",
"dev": "tsc -b --watch",
"start": "node ${INSPECT:-} --enable-source-maps dist/index.js",
"script:migrate-ticket": "node ${INSPECT:-} --enable-source-maps dist/scripts/migrate-ticket.js",
"script:reprocess-closed-ticket-by-range": "node ${INSPECT:-} --enable-source-maps dist/scripts/reprocess-closed-ticket-by-range.js",
"script:archive-ticket": "node ${INSPECT:-} --enable-source-maps dist/scripts/archive-ticket.js",
"test": "$npm_execpath run build test && c8 ava",
"test:debug": "ava -T 60m -svc 1 --no-worker-threads",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,55 @@
* limitations under the License.
*/
/* eslint-disable no-process-exit, unicorn/no-process-exit */
import { argv } from 'node:process';
import { config } from '../config.js';
import { connect } from '@oada/client';
import { doJob } from '@oada/client/jobs';
import { getTicket } from '../zd/zendesk.js';

import { pino } from '@oada/pino-debug';
const log = pino({ base: { script: argv[1] } });

if (argv.length !== 4) {
log.error(
'USAGE: node reprocess-closed-ticket-range.ts startTicketID stopTicketID',
);
process.exit(1);
}

const start = Number(argv[2]);
const stop = Number(argv[3]);

const log = pino();
const { token, domain } = config.get('oada');
const oada = await connect({ token, domain });

async function* ticketCounter() {
for (let id = 7070; id <= 10_000; id++) {
for (let id = start; id <= stop; id++) {
yield id;
}
}

const oada = await connect({
domain: config.get('oada.domain'),
token: config.get('oada.token'),
});

log.info({ start, stop }, 'Starting loop over tickets');
for await (const id of ticketCounter()) {
try {
log.info(`Processing ticket ID: ${id}`);
log.info(`Checking ticket ID: ${id}`);
const ticket = await getTicket(log, id);

if (ticket.status !== 'closed') {
log.info('Skipping NOT closed ticket.');
continue;
}

try {
await doJob(oada, {
service: 'zendesk-sync',
type: 'syncTicket',
config: {
ticketId: ticket.id,
archivers: [],
},
});
} catch (error) {
doJob(oada, {
service: 'zendesk-sync',
type: 'syncTicket',
config: {
ticketId: ticket.id,
archivers: [],
},
}).catch((error) => {
log.error({ ticketId: id }, `${error}`);

process.exit();
}
});
} catch {
log.info({ ticketId: id }, 'Not a ticket');
}
Expand Down

0 comments on commit e029b0d

Please sign in to comment.