Skip to content

Commit

Permalink
added column to limit # of times the cron executes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsharma1100 committed Jul 21, 2022
1 parent 4b2a2a9 commit a8e42f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 49 deletions.
67 changes: 18 additions & 49 deletions Cron/UpdateOrdersToProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UpdateOrdersToProcessing {
protected const STATUS_CANCELED = 'canceled';
protected const STATE_NEW = 'new';

protected const PROCESS_ORDER_WAIT_TIME = 5;
protected const PROCESS_ORDER_WAIT_TIME = 5 * 60;

/**
* CancelOrder constructor.
Expand Down Expand Up @@ -105,15 +105,20 @@ public function execute()
{
$this->logger->info("Cronjob: Update Orders To Processing Cron started.");

$dateTimeCheck = date('Y-m-d H:i:s', strtotime('-' . static::PROCESS_ORDER_WAIT_TIME . ' minutes'));
$dateTimeCheck = time() - static::PROCESS_ORDER_WAIT_TIME;
$sortOrder = $this->sortOrderBuilder->setField('entity_id')->setDirection('DESC')->create();

$this->logger->info($dateTimeCheck);
$searchCriteria = $this->searchCriteriaBuilder
->addFilter(
'updated_at',
'rzp_update_order_cron_status',
6,
'lt'
)->addFilter(
'rzp_webhook_notified_at', //rzp_webhook_notified_at
$dateTimeCheck,
'lt')
->addFilter(
'lt'
)->addFilter(
'status',
static::STATUS_PENDING,
'eq'
Expand Down Expand Up @@ -148,11 +153,11 @@ public function execute()
private function updateOrderStatus($order, $rzpWebhookData)
{
$this->logger->info("Cronjob: Updating to Processing for Order ID: "
. $order->getEntityId()
. " and Event :"
. $rzpWebhookData['event']
. " started."
);
. $order->getEntityId()
. " and Event :"
. $rzpWebhookData['event']
. " started."
);

$payment = $order->getPayment();
$paymentId = $rzpWebhookData['payment_id'];
Expand Down Expand Up @@ -255,51 +260,15 @@ private function updateOrderStatus($order, $rzpWebhookData)
}
}
}

$cronRunCount = $order->getRzpUpdateOrderCronStatus();
$order->setRzpUpdateOrderCronStatus($cronRunCount+1);
$order->save();

$this->logger->info("Cronjob: Updating to Processing for Order ID: "
. $order->getEntityId()
. " and Event :"
. $rzpWebhookData['event']
. " ended."
);
);
}

// /**
// * Get the Order from RZP
// *
// * @param string $orderId
// */
// public function getRzpOrder($orderId)
// {
// try
// {
// $order = $this->api->order->fetch($orderId);
// return $order;
// }
// catch (\Razorpay\Api\Errors\Error $e)
// {
// $this->logger->critical("Razorpay Webhook: fetching RZP order "
// . "data(id:$orderId) failed with error: ". $e->getMessage());
// return;
// }
// catch (\Exception $e)
// {
// $this->logger->critical("Razorpay Webhook: fetching RZP order "
// . "data(id:$orderId) failed with error: ". $e->getMessage());
// return;
// }
// }

// protected function getOrderWebhookData($orderId) : array
// {
// $collection = $this->objectManagement->get('Magento\Sales\Model\Order')
// ->getCollection()
// ->addFieldToSelect('entity_id')
// ->addFieldToSelect('rzp_webhook_notified_at')
// ->addFilter('increment_id', $orderId)
// ->getFirstItem();
// return $collection->getData();
// }
}
11 changes: 11 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function upgrade(SchemaSetupInterface $setup,
'comment' => 'RZP Webhook Data'
]
);

$setup->getConnection()->addColumn(
$tableName,
'rzp_update_order_cron_status',
[
'nullable' => false,
'default' => 0,
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
'comment' => 'RZP Update Order Processing Cron # of times executed'
]
);
}

$setup->endSetup();
Expand Down

0 comments on commit a8e42f5

Please sign in to comment.