@@ -36,63 +36,63 @@ |
||
| 36 | 36 | * @since 15.0.0 |
| 37 | 37 | */ |
| 38 | 38 | abstract class TimedJob extends Job { |
| 39 | - /** @var int */ |
|
| 40 | - protected $interval = 0; |
|
| 41 | - /** @var int */ |
|
| 42 | - protected $timeSensitivity = IJob::TIME_SENSITIVE; |
|
| 39 | + /** @var int */ |
|
| 40 | + protected $interval = 0; |
|
| 41 | + /** @var int */ |
|
| 42 | + protected $timeSensitivity = IJob::TIME_SENSITIVE; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * set the interval for the job |
|
| 46 | - * |
|
| 47 | - * @param int $seconds the time to pass between two runs of the same job in seconds |
|
| 48 | - * |
|
| 49 | - * @since 15.0.0 |
|
| 50 | - */ |
|
| 51 | - public function setInterval(int $seconds) { |
|
| 52 | - $this->interval = $seconds; |
|
| 53 | - } |
|
| 44 | + /** |
|
| 45 | + * set the interval for the job |
|
| 46 | + * |
|
| 47 | + * @param int $seconds the time to pass between two runs of the same job in seconds |
|
| 48 | + * |
|
| 49 | + * @since 15.0.0 |
|
| 50 | + */ |
|
| 51 | + public function setInterval(int $seconds) { |
|
| 52 | + $this->interval = $seconds; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Whether the background job is time sensitive and needs to run soon after |
|
| 57 | - * the scheduled interval, of if it is okay to be delayed until a later time. |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - * @since 24.0.0 |
|
| 61 | - */ |
|
| 62 | - public function isTimeSensitive(): bool { |
|
| 63 | - return $this->timeSensitivity === IJob::TIME_SENSITIVE; |
|
| 64 | - } |
|
| 55 | + /** |
|
| 56 | + * Whether the background job is time sensitive and needs to run soon after |
|
| 57 | + * the scheduled interval, of if it is okay to be delayed until a later time. |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + * @since 24.0.0 |
|
| 61 | + */ |
|
| 62 | + public function isTimeSensitive(): bool { |
|
| 63 | + return $this->timeSensitivity === IJob::TIME_SENSITIVE; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * If your background job is not time sensitive (sending instant email |
|
| 68 | - * notifications, etc.) it would be nice to set it to IJob::TIME_INSENSITIVE |
|
| 69 | - * This way the execution can be delayed during high usage times. |
|
| 70 | - * |
|
| 71 | - * @param int $sensitivity |
|
| 72 | - * @psalm-param IJob::TIME_* $sensitivity |
|
| 73 | - * @return void |
|
| 74 | - * @since 24.0.0 |
|
| 75 | - */ |
|
| 76 | - public function setTimeSensitivity(int $sensitivity): void { |
|
| 77 | - if ($sensitivity !== IJob::TIME_SENSITIVE && |
|
| 78 | - $sensitivity !== IJob::TIME_INSENSITIVE) { |
|
| 79 | - throw new \InvalidArgumentException('Invalid sensitivity'); |
|
| 80 | - } |
|
| 66 | + /** |
|
| 67 | + * If your background job is not time sensitive (sending instant email |
|
| 68 | + * notifications, etc.) it would be nice to set it to IJob::TIME_INSENSITIVE |
|
| 69 | + * This way the execution can be delayed during high usage times. |
|
| 70 | + * |
|
| 71 | + * @param int $sensitivity |
|
| 72 | + * @psalm-param IJob::TIME_* $sensitivity |
|
| 73 | + * @return void |
|
| 74 | + * @since 24.0.0 |
|
| 75 | + */ |
|
| 76 | + public function setTimeSensitivity(int $sensitivity): void { |
|
| 77 | + if ($sensitivity !== IJob::TIME_SENSITIVE && |
|
| 78 | + $sensitivity !== IJob::TIME_INSENSITIVE) { |
|
| 79 | + throw new \InvalidArgumentException('Invalid sensitivity'); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->timeSensitivity = $sensitivity; |
|
| 83 | - } |
|
| 82 | + $this->timeSensitivity = $sensitivity; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * run the job if the last run is is more than the interval ago |
|
| 87 | - * |
|
| 88 | - * @param JobList $jobList |
|
| 89 | - * @param ILogger|null $logger |
|
| 90 | - * |
|
| 91 | - * @since 15.0.0 |
|
| 92 | - */ |
|
| 93 | - final public function execute($jobList, ILogger $logger = null) { |
|
| 94 | - if (($this->time->getTime() - $this->lastRun) > $this->interval) { |
|
| 95 | - parent::execute($jobList, $logger); |
|
| 96 | - } |
|
| 97 | - } |
|
| 85 | + /** |
|
| 86 | + * run the job if the last run is is more than the interval ago |
|
| 87 | + * |
|
| 88 | + * @param JobList $jobList |
|
| 89 | + * @param ILogger|null $logger |
|
| 90 | + * |
|
| 91 | + * @since 15.0.0 |
|
| 92 | + */ |
|
| 93 | + final public function execute($jobList, ILogger $logger = null) { |
|
| 94 | + if (($this->time->getTime() - $this->lastRun) > $this->interval) { |
|
| 95 | + parent::execute($jobList, $logger); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -32,24 +32,24 @@ |
||
| 32 | 32 | use OCP\Migration\SimpleMigrationStep; |
| 33 | 33 | |
| 34 | 34 | class Version24000Date20220131153041 extends SimpleMigrationStep { |
| 35 | - /** |
|
| 36 | - * @param IOutput $output |
|
| 37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 38 | - * @param array $options |
|
| 39 | - * @return null|ISchemaWrapper |
|
| 40 | - */ |
|
| 41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 42 | - /** @var ISchemaWrapper $schema */ |
|
| 43 | - $schema = $schemaClosure(); |
|
| 35 | + /** |
|
| 36 | + * @param IOutput $output |
|
| 37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 38 | + * @param array $options |
|
| 39 | + * @return null|ISchemaWrapper |
|
| 40 | + */ |
|
| 41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 42 | + /** @var ISchemaWrapper $schema */ |
|
| 43 | + $schema = $schemaClosure(); |
|
| 44 | 44 | |
| 45 | - $table = $schema->getTable('jobs'); |
|
| 46 | - if (!$table->hasColumn('time_sensitive')) { |
|
| 47 | - $table->addColumn('time_sensitive', Types::SMALLINT, [ |
|
| 48 | - 'default' => 1, |
|
| 49 | - ]); |
|
| 50 | - $table->addIndex(['time_sensitive'], 'jobs_time_sensitive'); |
|
| 51 | - return $schema; |
|
| 52 | - } |
|
| 53 | - return null; |
|
| 54 | - } |
|
| 45 | + $table = $schema->getTable('jobs'); |
|
| 46 | + if (!$table->hasColumn('time_sensitive')) { |
|
| 47 | + $table->addColumn('time_sensitive', Types::SMALLINT, [ |
|
| 48 | + 'default' => 1, |
|
| 49 | + ]); |
|
| 50 | + $table->addIndex(['time_sensitive'], 'jobs_time_sensitive'); |
|
| 51 | + return $schema; |
|
| 52 | + } |
|
| 53 | + return null; |
|
| 54 | + } |
|
| 55 | 55 | } |