Skip to content

Commit

Permalink
Merge pull request #186 from magento-api/Accept-Public-PRs
Browse files Browse the repository at this point in the history
[GitHub] Accept github pull requests 1088, 1052, 987
  • Loading branch information
Tulika,Eugene(etulika) committed Mar 20, 2015
2 parents ad5e6b2 + 339d0ad commit b10a27b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
############################################
## uncomment the line below to enable developer mode

# SetEnv MAGE_MODE developer

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
Expand Down Expand Up @@ -167,6 +172,8 @@
## http://developer.yahoo.com/performance/rules.html#expires

ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0

</IfModule>

Expand Down
7 changes: 7 additions & 0 deletions .htaccess.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
############################################
## uncomment the line below to enable developer mode

# SetEnv MAGE_MODE developer

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
Expand Down Expand Up @@ -164,6 +169,8 @@
## http://developer.yahoo.com/performance/rules.html#expires

ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0

</IfModule>

Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/Cron/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ protected function _cleanup($groupId)
return $this;
}

// check how long the record should stay unprocessed before marked as MISSED
$scheduleLifetime = (int)$this->_scopeConfig->getValue(
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;

/**
* @var \Magento\Cron\Model\Resource\Schedule\Collection $history
*/
Expand All @@ -370,7 +377,9 @@ protected function _cleanup($groupId)
$now = $this->timezone->scopeTimeStamp();
/** @var Schedule $record */
foreach ($history as $record) {
if (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()]) {
$checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) :
strtotime($record->getScheduledAt()) + $scheduleLifetime;
if ($checkTime < $now - $historyLifetimes[$record->getStatus()]) {
$record->delete();
}
}
Expand Down
82 changes: 82 additions & 0 deletions app/code/Magento/Cron/Test/Unit/Model/ObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Cron\Test\Unit\Model;

use Magento\Cron\Model\Schedule;

/**
* Class \Magento\Cron\Test\Unit\Model\ObserverTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -607,4 +609,84 @@ public function testDispatchCleanup()

$this->_observer->dispatch('');
}

public function testMissedJobsCleanedInTime()
{
/* 1. Initialize dependencies of _generate() method which is called first */
$jobConfig = [
'test_group' => ['test_job1' => ['instance' => 'CronJob', 'method' => 'execute']],
];

// This item was scheduled 2 days ago
$schedule1 = $this->getMockBuilder(
'Magento\Cron\Model\Schedule'
)->disableOriginalConstructor()->setMethods(
['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup']
)->getMock();
$schedule1->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
$schedule1->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-2 day -1 hour'));
$schedule1->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
//we expect this job be deleted from the list
$schedule1->expects($this->once())->method('delete')->will($this->returnValue(true));

// This item was scheduled 1 day ago
$schedule2 = $this->getMockBuilder(
'Magento\Cron\Model\Schedule'
)->disableOriginalConstructor()->setMethods(
['getExecutedAt', 'getScheduledAt', 'getStatus', 'delete', '__wakeup']
)->getMock();
$schedule2->expects($this->any())->method('getExecutedAt')->will($this->returnValue(null));
$schedule2->expects($this->any())->method('getScheduledAt')->will($this->returnValue('-1 day'));
$schedule2->expects($this->any())->method('getStatus')->will($this->returnValue(Schedule::STATUS_MISSED));
//we don't expect this job be deleted from the list
$schedule2->expects($this->never())->method('delete');

$this->_collection->addItem($schedule1);
$this->_config->expects($this->once())->method('getJobs')->will($this->returnValue($jobConfig));

//get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_generate()"
$this->_cache->expects($this->at(0))->method('load')->will($this->returnValue(time() + 10000000));
//get configuration value CACHE_KEY_LAST_HISTORY_CLEANUP_AT in the "_cleanup()"
$this->_cache->expects($this->at(1))->method('load')->will($this->returnValue(time() - 10000000));

$this->_scopeConfig->expects($this->at(0))->method('getValue')
->with($this->equalTo('system/cron/test_group/use_separate_process'))
->will($this->returnValue(0));
$this->_scopeConfig->expects($this->at(1))->method('getValue')
->with($this->equalTo('system/cron/test_group/schedule_generate_every'))
->will($this->returnValue(0));
$this->_scopeConfig->expects($this->at(2))->method('getValue')
->with($this->equalTo('system/cron/test_group/history_cleanup_every'))
->will($this->returnValue(0));
$this->_scopeConfig->expects($this->at(3))->method('getValue')
->with($this->equalTo('system/cron/test_group/schedule_lifetime'))
->will($this->returnValue(2*24*60));
$this->_scopeConfig->expects($this->at(4))->method('getValue')
->with($this->equalTo('system/cron/test_group/history_success_lifetime'))
->will($this->returnValue(0));
$this->_scopeConfig->expects($this->at(5))->method('getValue')
->with($this->equalTo('system/cron/test_group/history_failure_lifetime'))
->will($this->returnValue(0));

/* 2. Initialize dependencies of _cleanup() method which is called second */
$scheduleMock = $this->getMockBuilder('Magento\Cron\Model\Schedule')->disableOriginalConstructor()->getMock();
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
$this->_scheduleFactory->expects($this->at(0))->method('create')->will($this->returnValue($scheduleMock));

$collection = $this->getMockBuilder(
'Magento\Cron\Model\Resource\Schedule\Collection'
)->setMethods(
['addFieldToFilter', 'load', '__wakeup']
)->disableOriginalConstructor()->getMock();
$collection->expects($this->any())->method('addFieldToFilter')->will($this->returnSelf());
$collection->expects($this->any())->method('load')->will($this->returnSelf());
$collection->addItem($schedule1);
$collection->addItem($schedule2);

$scheduleMock = $this->getMockBuilder('Magento\Cron\Model\Schedule')->disableOriginalConstructor()->getMock();
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($collection));
$this->_scheduleFactory->expects($this->at(1))->method('create')->will($this->returnValue($scheduleMock));

$this->_observer->dispatch('');
}
}
4 changes: 3 additions & 1 deletion dev/tests/functional/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
## http://developer.yahoo.com/performance/rules.html#expires

ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0

</IfModule>

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

#FileETag none
#FileETag none
1 change: 1 addition & 0 deletions nginx.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ location / {
}

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

fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
Expand Down
7 changes: 7 additions & 0 deletions pub/.htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
############################################
## uncomment the line below to enable developer mode

# SetEnv MAGE_MODE developer

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
Expand Down Expand Up @@ -153,6 +158,8 @@
## http://developer.yahoo.com/performance/rules.html#expires

ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0

</IfModule>

Expand Down

0 comments on commit b10a27b

Please sign in to comment.