From 91c545f9612198da0f3b15a8b552324adca1e003 Mon Sep 17 00:00:00 2001 From: Mentor Date: Mon, 22 Aug 2022 15:20:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20logging=20trail=20for=20retries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/nft-media/changing-room.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/nft-media/changing-room.js b/functions/nft-media/changing-room.js index 6aaf198..1e7290a 100644 --- a/functions/nft-media/changing-room.js +++ b/functions/nft-media/changing-room.js @@ -9,17 +9,22 @@ const { notify_discord_of_new_outfit } = require( '../integrations/discord' ) // /////////////////////////////// async function getRocketeerIfOutfitAvailable( id, network='mainnet', retry=false ) { + if( retry ) console.log( `Retry of getRocketeerIfOutfitAvailable for ${ id } on ${ network }` ) + const newOutfitAllowedInterval = 1000 * 60 * 60 * 24 * 30 // Retreive old Rocketeer data const rocketeer = await db.collection( `${ network }Rocketeers` ).doc( id ).get().then( dataFromSnap ) + // If this is a retry attempt, skip last change validation + if( retry ) return rocketeer + // Validate this request const { value: last_outfit_change } = rocketeer.attributes.find( ( { trait_type } ) => trait_type == "last outfit change" ) || { value: 0 } // Check whether this Rocketeer is allowed to change const timeUntilAllowedToChange = newOutfitAllowedInterval - ( Date.now() - last_outfit_change ) - if( !retry && timeUntilAllowedToChange > 0 ) throw new Error( `You changed your outfit too recently, a change is avalable in ${ Math.floor( timeUntilAllowedToChange / ( 1000 * 60 * 60 ) ) } hours (${ new Date( Date.now() + timeUntilAllowedToChange ).toString() })` ) + if( timeUntilAllowedToChange > 0 ) throw new Error( `You changed your outfit too recently, a change is avalable in ${ Math.floor( timeUntilAllowedToChange / ( 1000 * 60 * 60 ) ) } hours (${ new Date( Date.now() + timeUntilAllowedToChange ).toString() })` ) return rocketeer @@ -192,6 +197,8 @@ async function handleQueuedRocketeerOutfit( change, context ) { const { rocketeerId } = context.params const { network, running, address, retry } = change.after.data() + if( retry ) console.log( `Document change for ${network}QueueOutfitGeneration/${rocketeerId} is a retry attempt` ) + try { /////