Skip to content

Commit b10a27b

Browse files
author
Tulika,Eugene(etulika)
committed
Merge pull request #186 from magento-api/Accept-Public-PRs
[GitHub] Accept github pull requests 1088, 1052, 987
2 parents ad5e6b2 + 339d0ad commit b10a27b

File tree

7 files changed

+117
-2
lines changed

7 files changed

+117
-2
lines changed

.htaccess

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
############################################
2+
## uncomment the line below to enable developer mode
3+
4+
# SetEnv MAGE_MODE developer
5+
16
############################################
27
## uncomment these lines for CGI mode
38
## make sure to specify the correct cgi php binary file name
@@ -167,6 +172,8 @@
167172
## http://developer.yahoo.com/performance/rules.html#expires
168173

169174
ExpiresDefault "access plus 1 year"
175+
ExpiresByType text/html A0
176+
ExpiresByType text/plain A0
170177

171178
</IfModule>
172179

.htaccess.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
############################################
2+
## uncomment the line below to enable developer mode
3+
4+
# SetEnv MAGE_MODE developer
5+
16
############################################
27
## uncomment these lines for CGI mode
38
## make sure to specify the correct cgi php binary file name
@@ -164,6 +169,8 @@
164169
## http://developer.yahoo.com/performance/rules.html#expires
165170

166171
ExpiresDefault "access plus 1 year"
172+
ExpiresByType text/html A0
173+
ExpiresByType text/plain A0
167174

168175
</IfModule>
169176

app/code/Magento/Cron/Model/Observer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ protected function _cleanup($groupId)
345345
return $this;
346346
}
347347

348+
// check how long the record should stay unprocessed before marked as MISSED
349+
$scheduleLifetime = (int)$this->_scopeConfig->getValue(
350+
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME,
351+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
352+
);
353+
$scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
354+
348355
/**
349356
* @var \Magento\Cron\Model\Resource\Schedule\Collection $history
350357
*/
@@ -370,7 +377,9 @@ protected function _cleanup($groupId)
370377
$now = $this->timezone->scopeTimeStamp();
371378
/** @var Schedule $record */
372379
foreach ($history as $record) {
373-
if (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) {
380+
$checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) :
381+
strtotime($record->getScheduledAt()) + $scheduleLifetime;
382+
if ($checkTime < $now - $historyLifetimes[$record->getStatus()]) {
374383
$record->delete();
375384
}
376385
}

app/code/Magento/Cron/Test/Unit/Model/ObserverTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cron\Test\Unit\Model;
77

8+
use Magento\Cron\Model\Schedule;
9+
810
/**
911
* Class \Magento\Cron\Test\Unit\Model\ObserverTest
1012
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -607,4 +609,84 @@ public function testDispatchCleanup()
607609

608610
$this->_observer->dispatch('');
609611
}
612+
613+
public function testMissedJobsCleanedInTime()
614+
{
615+
/* 1. Initialize dependencies of _generate() method which is called first */
616+
$jobConfig = [
617+
'test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']],
618+
];
619+
620+
// This item was scheduled 2 days ago
621+
$schedule1 = $this->getMockBuilder(
622+
'Magento\Cron\Model\Schedule'
623+
)->disableOriginalConstructor()->setMethods(
624+
['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup']
625+
)->getMock();
626+
$schedule1->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
627+
$schedule1->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-2 day -1 hour'));
628+
$schedule1->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
629+
//we expect this job be deleted from the list
630+
$schedule1->expects($this->once())->method('delete')->will($this->returnValue(true));
631+
632+
// This item was scheduled 1 day ago
633+
$schedule2 = $this->getMockBuilder(
634+
'Magento\Cron\Model\Schedule'
635+
)->disableOriginalConstructor()->setMethods(
636+
['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup']
637+
)->getMock();
638+
$schedule2->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
639+
$schedule2->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-1 day'));
640+
$schedule2->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
641+
//we don't expect this job be deleted from the list
642+
$schedule2->expects($this->never())->method('delete');
643+
644+
$this->_collection->addItem($schedule1);
645+
$this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig));
646+
647+
//get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_generate()"
648+
$this->_cache->expects($this->at(0))->method('load')->will($this->returnValue(time() + 10000000));
649+
//get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_cleanup()"
650+
$this->_cache->expects($this->at(1))->method('load')->will($this->returnValue(time() - 10000000));
651+
652+
$this->_scopeConfig->expects($this->at(0))->method('getValue')
653+
->with($this->equalTo('system/cron/test_group/use_separate_process'))
654+
->will($this->returnValue(0));
655+
$this->_scopeConfig->expects($this->at(1))->method('getValue')
656+
->with($this->equalTo('system/cron/test_group/schedule_generate_every'))
657+
->will($this->returnValue(0));
658+
$this->_scopeConfig->expects($this->at(2))->method('getValue')
659+
->with($this->equalTo('system/cron/test_group/history_cleanup_every'))
660+
->will($this->returnValue(0));
661+
$this->_scopeConfig->expects($this->at(3))->method('getValue')
662+
->with($this->equalTo('system/cron/test_group/schedule_lifetime'))
663+
->will($this->returnValue(2*24*60));
664+
$this->_scopeConfig->expects($this->at(4))->method('getValue')
665+
->with($this->equalTo('system/cron/test_group/history_success_lifetime'))
666+
->will($this->returnValue(0));
667+
$this->_scopeConfig->expects($this->at(5))->method('getValue')
668+
->with($this->equalTo('system/cron/test_group/history_failure_lifetime'))
669+
->will($this->returnValue(0));
670+
671+
/* 2. Initialize dependencies of _cleanup() method which is called second */
672+
$scheduleMock = $this->getMockBuilder('Magento\Cron\Model\Schedule')->disableOriginalConstructor()->getMock();
673+
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
674+
$this->_scheduleFactory->expects($this->at(0))->method('create')->will($this->returnValue($scheduleMock));
675+
676+
$collection = $this->getMockBuilder(
677+
'Magento\Cron\Model\Resource\Schedule\Collection'
678+
)->setMethods(
679+
['addFieldToFilter', 'load', '__wakeup']
680+
)->disableOriginalConstructor()->getMock();
681+
$collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf());
682+
$collection->expects($this->any())->method('load')->will($this->returnSelf());
683+
$collection->addItem($schedule1);
684+
$collection->addItem($schedule2);
685+
686+
$scheduleMock = $this->getMockBuilder('Magento\Cron\Model\Schedule')->disableOriginalConstructor()->getMock();
687+
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($collection));
688+
$this->_scheduleFactory->expects($this->at(1))->method('create')->will($this->returnValue($scheduleMock));
689+
690+
$this->_observer->dispatch('');
691+
}
610692
}

dev/tests/functional/.htaccess

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170
## http://developer.yahoo.com/performance/rules.html#expires
171171

172172
ExpiresDefault "access plus 1 year"
173+
ExpiresByType text/html A0
174+
ExpiresByType text/plain A0
173175

174176
</IfModule>
175177

@@ -191,4 +193,4 @@
191193
## If running in cluster environment, uncomment this
192194
## http://developer.yahoo.com/performance/rules.html#etags
193195

194-
#FileETag none
196+
#FileETag none

nginx.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ location / {
127127
}
128128

129129
location ~ (index|get|static|report|404|503)\.php$ {
130+
expires -1;
130131
fastcgi_pass fastcgi_backend;
131132

132133
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";

pub/.htaccess

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
############################################
2+
## uncomment the line below to enable developer mode
3+
4+
# SetEnv MAGE_MODE developer
5+
16
############################################
27
## uncomment these lines for CGI mode
38
## make sure to specify the correct cgi php binary file name
@@ -153,6 +158,8 @@
153158
## http://developer.yahoo.com/performance/rules.html#expires
154159

155160
ExpiresDefault "access plus 1 year"
161+
ExpiresByType text/html A0
162+
ExpiresByType text/plain A0
156163

157164
</IfModule>
158165

0 commit comments

Comments
 (0)