How to use the @reactioncommerce/logger.trace function in @reactioncommerce/logger

To help you get started, we’ve selected a few @reactioncommerce/logger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / imports / node-app / plugins / simple-inventory / mutations / updateSimpleInventoryBulk.js View on Github external
const { productConfiguration, shopId } = update;
    bulkOperations.push({
      updateOne: {
        filter: {
          "productConfiguration.productVariantId": productConfiguration.productVariantId,
          shopId
        },
        update: modifier,
        upsert: true
      }
    });
  });

  let res;
  try {
    Logger.trace({ ...logCtx, bulkOperations }, "Running bulk op");
    res = await SimpleInventory.bulkWrite(bulkOperations, { ordered: false });
  } catch (error) {
    Logger.error({ ...logCtx, error }, "One or more of the bulk update failed");
    res = error; // error object has details about failed & successful operations
  }

  const upsertedIds = res.result.upserted.map((each) => each._id);
  const failedUpdates = validUpdates.filter((update) => {
    const match = res.result.writeErrors.find((writeError) => {
      const errVariantId = writeError.op.q["productConfiguration.productVariantId"];
      const updateVariantId = update.productConfiguration.productVariantId;
      return updateVariantId === errVariantId;
    });
    if (match) return true;
    return false;
  });
github reactioncommerce / reaction / imports / node-app / core-services / cart / mutations / saveManyCarts.js View on Github external
await context.mutations.transformAndValidateCart(context, cart);

    return {
      replaceOne: {
        filter: { _id: cart._id },
        replacement: cart,
        upsert: true
      }
    };
  });

  const bulkWrites = await Promise.all(bulkWritePromises);

  let writeErrors;
  try {
    Logger.trace({ ...logCtx, bulkWrites }, "Running bulk op");
    const bulkWriteResult = await Cart.bulkWrite(bulkWrites, { ordered: false });
    ({ writeErrors } = bulkWriteResult.result);
  } catch (error) {
    if (!error.result || typeof error.result.getWriteErrors !== "function") throw error;
    // This happens only if all writes fail. `error` object has the result on it.
    writeErrors = error.result.getWriteErrors();
  }

  // Figure out which failed and which succeeded. Emit "after update" or log error
  const cartIds = [];
  await Promise.all(carts.map(async (cart, index) => {
    // If updating this cart failed, log the error details and stop
    const writeError = writeErrors.find((writeErr) => writeErr.index === index);
    if (writeError) {
      Logger.error({
        ...logCtx,
github reactioncommerce / reaction / imports / node-app / core-services / product / utils / executeBulkOperation.js View on Github external
export default async function executeBulkOperation(collection, operations, totalProducts) {
  let response;
  try {
    Logger.trace({ ...logCtx, operations }, "Running bulk operation");
    response = await collection.bulkWrite(operations, { ordered: false });
  } catch (error) {
    Logger.error({ ...logCtx, error }, "One or more of the bulk update failed");
    response = error; // error object has details about failed & successful operations
  }

  const { nMatched, nModified, result: { writeErrors } } = response;
  const notFoundCount = totalProducts - nMatched;

  const cleanedErrors = writeErrors.map((error) => ({
    documentId: error.op._id,
    errorMsg: error.errmsg
  }));

  return {
    foundCount: nMatched,
github reactioncommerce / reaction / imports / node-app / plugins / simple-inventory / mutations / updateSimpleInventoryBulk.js View on Github external
upsertedDocsOpData.forEach((operationData) => {
      const arg = {
        productConfiguration: {
          productId: operationData.updateOne.update.$setOnInsert["productConfiguration.productId"],
          productVariantId: operationData.updateOne.filter["productConfiguration.productVariantId"]
        },
        shopId: operationData.updateOne.filter.shopId
      };
      Logger.trace({ ...logCtx, arg }, "Calling recalculateReservedSimpleInventory");
      context.mutations.recalculateReservedSimpleInventory(context, arg);
    });
  }

@reactioncommerce/logger

Reaction application logging based on Bunyan logger

MIT
Latest version published 3 years ago

Package Health Score

36 / 100
Full package analysis

Similar packages