Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - magento/magento2#22671: Change exportButton option cvs (by @ajeetsinghcedcoss)
 - magento/magento2#23312: Added function to check against running/pending/successful cron tasks (by @chickenland)
 - magento/magento2#23306: FS/23038 Decimal qty with Increment is with specific values are not adding in cart (by @sertlab)
 - magento/magento2#23280: Ensure page is loaded after order click actions (by @fooman)
 - magento/magento2#23240: Refactor: Improve mview code readability (by @lbajsarowicz)


Fixed GitHub Issues:
 - magento/magento2#21380: Cron schedule is being duplicated (reported by @udovicic) has been fixed in magento/magento2#23312 by @chickenland in 2.3-develop branch
   Related commits:
     1. 7859a2f
     2. dd5af3d
     3. 8ee5163
  • Loading branch information
magento-engcom-team authored Jun 26, 2019
2 parents d440559 + 98ec547 commit 21b3caf
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
<!-- Create invoice -->
<comment userInput="Create invoice" stepKey="createInvoice"/>
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoiceButton"/>
<waitForPageLoad stepKey="waitForInvoicePageToLoad"/>
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Invoice" stepKey="seeNewInvoiceInPageTitle" after="clickInvoiceButton"/>
<see selector="{{AdminInvoiceTotalSection.total('Subtotal')}}" userInput="$150.00" stepKey="seeCorrectGrandTotal"/>
<click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<click selector="{{AdminOrdersGridSection.submitSearch}}" stepKey="submitSearchOrderNum"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappearOnSearch"/>
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>

<!-- Checking the correctness of displayed custom options for user parameters on Order -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask4"/>

<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoice"/>
<waitForPageLoad stepKey="waitForNewInvoicePageToLoad"/>
<click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/>
<waitForPageLoad stepKey="waitForNewInvoiceToBeCreated"/>
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="The invoice has been created." stepKey="seeSuccessMessage"/>
<click selector="{{AdminOrderDetailsMainActionsSection.ship}}" stepKey="clickShip"/>
<waitForLoadingMaskToDisappear stepKey="waitForShipLoadingMask"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<click stepKey="s81" selector="{{AdminOrdersGridSection.submitSearch22}}" />
<waitForPageLoad stepKey="s831"/>
<click stepKey="s84" selector="{{AdminOrdersGridSection.firstRow}}" />
<waitForPageLoad stepKey="waitForOrderToLoad"/>
<see stepKey="s85" selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="Pending" />
<see stepKey="s87" selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="Customer" />
<see stepKey="s89" selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="$$simpleuscustomer.email$$" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<click selector="{{AdminOrdersGridSection.submitSearch}}" stepKey="submitSearchOrderNum"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappearOnSearch"/>
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<see selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="Pending" stepKey="seeAdminOrderStatus"/>
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="{{CustomerEntityOne.fullname}}" stepKey="seeAdminOrderGuest"/>
<see selector="{{AdminOrderDetailsInformationSection.accountInformation}}" userInput="{{CustomerEntityOne.email}}" stepKey="seeAdminOrderEmail"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
</actionGroup>

<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoiceButton"/>
<waitForPageLoad stepKey="waitForNewInvoicePageLoad"/>
<fillField selector="{{AdminInvoiceItemsSection.qtyToInvoiceColumn}}" userInput="1" stepKey="ChangeQtyToInvoice"/>
Expand Down
84 changes: 59 additions & 25 deletions app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* Handling cron jobs
*/
namespace Magento\Cron\Observer;

use Magento\Cron\Model\Schedule;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Framework\Event\ObserverInterface;
use Magento\Cron\Model\Schedule;
use Magento\Framework\Profiler\Driver\Standard\Stat;
use Magento\Framework\Profiler\Driver\Standard\StatFactory;

Expand Down Expand Up @@ -204,7 +203,6 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{

$currentTime = $this->dateTime->gmtTimestamp();
$jobGroupsRoot = $this->_config->getJobs();
// sort jobs groups to start from used in separated process
Expand Down Expand Up @@ -258,7 +256,6 @@ function ($groupId) use ($currentTime, $jobsRoot) {
*/
private function lockGroup($groupId, callable $callback)
{

if (!$this->lockManager->lock(self::LOCK_PREFIX . $groupId, self::LOCK_TIMEOUT)) {
$this->logger->warning(
sprintf(
Expand Down Expand Up @@ -293,17 +290,20 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
$scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
if ($scheduledTime < $currentTime - $scheduleLifetime) {
$schedule->setStatus(Schedule::STATUS_MISSED);
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(sprintf('Cron Job %s is missed at %s', $jobCode, $schedule->getScheduledAt()));
}

if (!isset($jobConfig['instance'], $jobConfig['method'])) {
$schedule->setStatus(Schedule::STATUS_ERROR);
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(sprintf('No callbacks found for cron job %s', $jobCode));
}
$model = $this->_objectManager->create($jobConfig['instance']);
$callback = [$model, $jobConfig['method']];
if (!is_callable($callback)) {
$schedule->setStatus(Schedule::STATUS_ERROR);
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(
sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method'])
);
Expand All @@ -314,15 +314,18 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
$this->startProfiling();
try {
$this->logger->info(sprintf('Cron Job %s is run', $jobCode));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array($callback, [$schedule]);
} catch (\Throwable $e) {
$schedule->setStatus(Schedule::STATUS_ERROR);
$this->logger->error(sprintf(
'Cron Job %s has an error: %s. Statistics: %s',
$jobCode,
$e->getMessage(),
$this->getProfilingStat()
));
$this->logger->error(
sprintf(
'Cron Job %s has an error: %s. Statistics: %s',
$jobCode,
$e->getMessage(),
$this->getProfilingStat()
)
);
if (!$e instanceof \Exception) {
$e = new \RuntimeException(
'Error when running a cron job',
Expand All @@ -335,16 +338,22 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
$this->stopProfiling();
}

$schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime(
'%Y-%m-%d %H:%M:%S',
$this->dateTime->gmtTimestamp()
));
$schedule->setStatus(
Schedule::STATUS_SUCCESS
)->setFinishedAt(
strftime(
'%Y-%m-%d %H:%M:%S',
$this->dateTime->gmtTimestamp()
)
);

$this->logger->info(sprintf(
'Cron Job %s is successfully finished. Statistics: %s',
$jobCode,
$this->getProfilingStat()
));
$this->logger->info(
sprintf(
'Cron Job %s is successfully finished. Statistics: %s',
$jobCode,
$this->getProfilingStat()
)
);
}

/**
Expand Down Expand Up @@ -395,6 +404,28 @@ private function getPendingSchedules($groupId)
return $pendingJobs;
}

/**
* Return job collection from database with status 'pending', 'running' or 'success'
*
* @param string $groupId
* @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
*/
private function getNonExitedSchedules($groupId)
{
$jobs = $this->_config->getJobs();
$pendingJobs = $this->_scheduleFactory->create()->getCollection();
$pendingJobs->addFieldToFilter(
'status',
[
'in' => [
Schedule::STATUS_PENDING, Schedule::STATUS_RUNNING, Schedule::STATUS_SUCCESS
]
]
);
$pendingJobs->addFieldToFilter('job_code', ['in' => array_keys($jobs[$groupId])]);
return $pendingJobs;
}

/**
* Generate cron schedule
*
Expand Down Expand Up @@ -426,7 +457,7 @@ private function generateSchedules($groupId)
null
);

$schedules = $this->getPendingSchedules($groupId);
$schedules = $this->getNonExitedSchedules($groupId);
$exists = [];
/** @var Schedule $schedule */
foreach ($schedules as $schedule) {
Expand Down Expand Up @@ -669,11 +700,14 @@ private function cleanupScheduleMismatches()
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
$scheduleResource = $this->_scheduleFactory->create()->getResource();
foreach ($this->invalid as $jobCode => $scheduledAtList) {
$scheduleResource->getConnection()->delete($scheduleResource->getMainTable(), [
'status = ?' => Schedule::STATUS_PENDING,
'job_code = ?' => $jobCode,
'scheduled_at in (?)' => $scheduledAtList,
]);
$scheduleResource->getConnection()->delete(
$scheduleResource->getMainTable(),
[
'status = ?' => Schedule::STATUS_PENDING,
'job_code = ?' => $jobCode,
'scheduled_at in (?)' => $scheduledAtList,
]
);
}
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask4"/>

<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoice"/>
<waitForPageLoad stepKey="waitForNewInvoicePageToLoad"/>
<click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/>
<waitForPageLoad stepKey="waitForInvoiceToBeCreated"/>
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="The invoice has been created." stepKey="seeSuccessMessage"/>
<click selector="{{AdminOrderDetailsOrderViewSection.invoices}}" stepKey="clickInvoices"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@

<!-- Create invoice -->
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
<waitForPageLoad stepKey="waitForOrderPageToLoad"/>
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoiceButton"/>
<waitForPageLoad stepKey="waitForNewInvoicePageToLoad"/>
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Invoice" stepKey="seeNewInvoiceInPageTitle" after="clickInvoiceButton"/>

<!-- Verify Invoice Totals including subTotal Shipping Discount and GrandTotal -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
<exportButton class="Magento\Ui\Component\ExportButton" component="Magento_Ui/js/grid/export" displayArea="dataGridActions">
<settings>
<options>
<option name="cvs" xsi:type="array">
<option name="csv" xsi:type="array">
<item name="value" xsi:type="string">csv</item>
<item name="label" xsi:type="string" translate="true">CSV</item>
<item name="url" xsi:type="string">mui/export/gridToCsv</item>
Expand Down
Loading

0 comments on commit 21b3caf

Please sign in to comment.