Extract common and task-specific methods for subscribers [MAILPOET-940]

This commit is contained in:
stoletniy
2017-07-12 10:33:26 +03:00
parent c02394b576
commit 55d3b67a2a
4 changed files with 83 additions and 37 deletions

View File

@@ -11,10 +11,6 @@ class ScheduledTask extends Model {
const PRIORITY_MEDIUM = 5;
const PRIORITY_LOW = 10;
function taskSubscribers() {
return $this->has_many(__NAMESPACE__ . '\ScheduledTaskSubscriber', 'task_id', 'id');
}
function complete() {
$this->set('status', self::STATUS_COMPLETED);
$this->save();
@@ -29,21 +25,4 @@ class ScheduledTask extends Model {
parent::save();
return $this;
}
function updateProcessedSubscribers(array $processed_subscribers) {
$this->taskSubscribers()
->whereIn('subscriber_id', $processed_subscribers)
->findResultSet()
->set('processed', ScheduledTaskSubscriber::STATUS_PROCESSED)
->save();
$this->checkCompleted();
}
private function checkCompleted() {
if(!ScheduledTaskSubscriber::getToProcessCount($this->id)) {
$this->processed_at = current_time('mysql');
$this->status = self::STATUS_COMPLETED;
return $this->save();
}
}
}