Added mtime support to Job Status object

Added a modified time column to the Job Status table and updated code to
match.
This commit is contained in:
2010-06-08 21:18:32 +01:00
parent 9cf50b9cfd
commit 04c95c6940

View File

@@ -20,13 +20,15 @@ class HandBrakeCluster_JobStatus {
protected $job_id;
protected $status;
protected $ctime;
protected $mtime;
protected $rip_progress;
protected function __construct($id, $job_id, $status, $ctime, $rip_progress) {
protected function __construct($id, $job_id, $status, $ctime, $mtime, $rip_progress) {
$this->id = $id;
$this->job_id = $job_id;
$this->status = $status;
$this->ctime = $ctime;
$this->mtime = $mtime;
$this->rip_progress = $rip_progress;
}
@@ -36,12 +38,14 @@ class HandBrakeCluster_JobStatus {
$row['job_id'],
$row['status'],
$row['ctime'],
$row['mtime'],
$row['rip_progress']
);
}
public static function updateStatusForJob($job, $status, $rip_progress = null) {
$status = new HandBrakeCluster_JobStatus(null, $job->id(), $status, time(), $rip_progress);
$ctime = $mtime = time();
$status = new HandBrakeCluster_JobStatus(null, $job->id(), $status, $ctime, $mtime, $rip_progress);
$status->create();
return $status;
@@ -49,6 +53,7 @@ class HandBrakeCluster_JobStatus {
public function updateRipProgress($rip_progress) {
$this->rip_progress = $rip_progress;
$this->mtime = time();
$this->save();
}
@@ -56,7 +61,7 @@ class HandBrakeCluster_JobStatus {
$statuses = array();
$database = HandBrakeCluster_Main::instance()->database();
foreach ($database->selectList('SELECT * FROM job_status WHERE job_id=:job_id ORDER BY ctime ASC', array(
foreach ($database->selectList('SELECT * FROM job_status WHERE job_id=:job_id ORDER BY mtime ASC', array(
array('name' => 'job_id', 'value' => $job->id(), 'type' => PDO::PARAM_INT),
)) as $row) {
$statuses[] = HandBrakeCluster_JobStatus::fromDatabaseRow($row);
@@ -69,12 +74,13 @@ class HandBrakeCluster_JobStatus {
$database = HandBrakeCluster_Main::instance()->database();
$database->insert(
'INSERT INTO job_status
(id, job_id, status, ctime, rip_progress)
VALUES(NULL,:job_id,:status,:ctime,:rip_progress)',
(id, job_id, status, ctime, mtime, rip_progress)
VALUES(NULL,:job_id,:status,:ctime,:mtime,:rip_progress)',
array(
array(name => 'job_id', value => $this->job_id, type => PDO::PARAM_INT),
array(name => 'status', value => $this->status, type => PDO::PARAM_INT),
array(name => 'ctime', value => $this->ctime, type => PDO::PARAM_INT),
array(name => 'mtime', value => $this->mtime, type => PDO::PARAM_INT),
array(name => 'rip_progress', value => $this->rip_progress),
)
);
@@ -86,18 +92,23 @@ class HandBrakeCluster_JobStatus {
$database = HandBrakeCluster_Main::instance()->database();
$database->update(
'UPDATE job_status SET
job_id=:job_id, status=:status, ctime=:ctime, rip_progress=:rip_progress
job_id=:job_id, status=:status, ctime=:ctime, mtime=:mtime, rip_progress=:rip_progress
WHERE id=:id',
array(
array(name => 'id', value => $this->id, type => PDO::PARAM_INT),
array(name => 'job_id', value => $this->job_id, type => PDO::PARAM_INT),
array(name => 'status', value => $this->status, type => PDO::PARAM_INT),
array(name => 'ctime', value => $this->ctime, type => PDO::PARAM_INT),
array(name => 'mtime', value => $this->mtime, type => PDO::PARAM_INT),
array(name => 'rip_progress', value => $this->rip_progress),
)
);
}
public function hasProgressInfo() {
return ($this->status == self::RUNNING);
}
public function id() {
return $this->id;
}
@@ -118,6 +129,10 @@ class HandBrakeCluster_JobStatus {
return $this->ctime;
}
public function mtime() {
return $this->mtime;
}
public function ripProgress() {
return $this->rip_progress;
}