Skip to content

Commit

Permalink
fix(cron-events): updates the execution check inside the function
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Aug 13, 2024
1 parent dc08eed commit b2e96bc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions functions/lib/cron-events-horus.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,20 @@ const productsPriceEvents = async (horus, storeId, opts) => {
const updatedAtDoc = data?.updated_at && new Date(data?.updated_at)
const now = new Date()

isExec = Boolean(hasRepeatDoc || (now.getTime() >= (updatedAtDoc.getTime() + (5 * 60 * 1000))))
if (hasRepeatDoc || updatedAtDoc) {
isExec = Boolean(hasRepeatDoc || (now.getTime() >= (updatedAtDoc.getTime() + (24 * 60 * 60 * 1000))))
}

if (hasRepeatDoc) {
dateInit = dateInitDoc ? new Date(dateInitDoc) : dateInit
dateEnd = dateEndtDoc ? new Date(dateEndtDoc) : dateEnd
offset = offsetDoc || 0
} else {
dateInit = dateEndtDoc ? new Date(dateEndtDoc) : dateEnd
}

console.log(`isExec: ${isExec} upDoc: ${updatedAtDoc.toISOString()} now ${now.toISOString()}`)
}

// Runs if there are repeats or every 24 hours
if (isExec) {
const codCaract = opts?.appData?.code_characteristic || 5
const codTpoCaract = opts?.appData?.code_type_characteristic || 3
Expand Down Expand Up @@ -293,12 +295,8 @@ module.exports = async (appSdk) => {
console.log('>> Horus API', isHorusApiOk ? 'OK' : 'OffLine')
if (isHorusApiOk) {
promises.push(productsStocksEvents(horus, storeId, opts))
// console.log(`horas : ${now.getHours() - 3}`)
// if ((now.getHours() - 3) === 12 && now.getMinutes() % 5 === 0) {
// if (now.getMinutes() % 10 === 0) {
// run at 3 am (UTC -3) everyday
// check in the function
promises.push(productsPriceEvents(horus, storeId, opts))
// }

const now = new Date()
if (now.getMinutes() % 30 === 0) {
Expand Down

0 comments on commit b2e96bc

Please sign in to comment.