+ /**
+ * Attempt to deliver any redeemed but un-delivered ticket tokens.
+ */
+ async publishTickets() {
+ const _scope = _fileScope('publishTickets');
+ this.logger.debug(_scope, 'called');
+
+ try {
+ const queueName = this.options.queues.ticketRedeemedName;
+ await this.db.context(async (dbCtx) => {
+ const ticketTokens = await this.db.ticketTokenGetUnpublished(dbCtx);
+ for await (const data of ticketTokens) {
+ try {
+ const result = await this.queuePublisher.publish(queueName, data);
+ this.logger.info(_scope, 'published ticket token', { queueName, result, ...data });
+ const redeemedData = common.pick(data, ['resource', 'subject', 'iss', 'ticket', 'token']);
+ await this.db.ticketTokenPublished(dbCtx, redeemedData);
+ } catch (e) {
+ this.logger.error(_scope, 'publish failed', { error: e, data });
+ }
+ }
+ }); // dbCtx
+ } catch (e) {
+ this.logger.error(_scope, 'failed', { error: e });
+ throw e;
+ }
+ }
+} // Chores
+
+module.exports = Chores;