Added QueueManager to process background jobs
This commit is contained in:
33
app/Job/BaseJob.php
Normal file
33
app/Job/BaseJob.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Class BaseJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
abstract class BaseJob extends Base
|
||||
{
|
||||
/**
|
||||
* Job parameters
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $jobParams = array();
|
||||
|
||||
/**
|
||||
* Get job parameters
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getJobParams()
|
||||
{
|
||||
return $this->jobParams;
|
||||
}
|
||||
}
|
||||
54
app/Job/EmailJob.php
Normal file
54
app/Job/EmailJob.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
/**
|
||||
* Class EmailJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class EmailJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @access public
|
||||
* @param string $email
|
||||
* @param string $name
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $author
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($email, $name, $subject, $html, $author)
|
||||
{
|
||||
$this->jobParams = array($email, $name, $subject, $html, $author);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @access public
|
||||
* @param string $email
|
||||
* @param string $name
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param string $author
|
||||
*/
|
||||
public function execute($email, $name, $subject, $html, $author)
|
||||
{
|
||||
$this->logger->debug(__METHOD__.' Sending email to '.$email.' via '.MAIL_TRANSPORT);
|
||||
$startTime = microtime(true);
|
||||
|
||||
$this->emailClient
|
||||
->getTransport(MAIL_TRANSPORT)
|
||||
->sendEmail($email, $name, $subject, $html, $author)
|
||||
;
|
||||
|
||||
if (DEBUG) {
|
||||
$this->logger->debug('Email sent in '.round(microtime(true) - $startTime, 6).' seconds');
|
||||
}
|
||||
}
|
||||
}
|
||||
40
app/Job/ProjectMetricJob.php
Normal file
40
app/Job/ProjectMetricJob.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
/**
|
||||
* Class ProjectMetricJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectMetricJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job parameters
|
||||
*
|
||||
* @access public
|
||||
* @param integer $projectId
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($projectId)
|
||||
{
|
||||
$this->jobParams = array($projectId);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @access public
|
||||
* @param integer $projectId
|
||||
*/
|
||||
public function execute($projectId)
|
||||
{
|
||||
$this->logger->debug(__METHOD__.' Run project metrics calculation');
|
||||
$now = date('Y-m-d');
|
||||
|
||||
$this->projectDailyColumnStats->updateTotals($projectId, $now);
|
||||
$this->projectDailyStats->updateTotals($projectId, $now);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user