-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a basic scheduler for managing crontab and repeating task…
…s on the server
- Loading branch information
1 parent
a6b29be
commit 4a09c48
Showing
12 changed files
with
486 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Oak\Contracts\Scheduler; | ||
|
||
interface JobInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getCronExpression(): string; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommand(): string; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function execute(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Oak\Contracts\Scheduler; | ||
|
||
use Oak\Contracts\Console\OutputInterface; | ||
|
||
interface SchedulerInterface | ||
{ | ||
/** | ||
* @param string $command | ||
* @return JobInterface | ||
*/ | ||
public function run(string $command): JobInterface; | ||
|
||
/** | ||
* @param JobInterface $job | ||
* @return mixed | ||
*/ | ||
public function isDue(JobInterface $job); | ||
|
||
/** | ||
* @param OutputInterface $output | ||
* @return mixed | ||
*/ | ||
public function runSchedule(OutputInterface $output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Oak\Scheduler\Console; | ||
|
||
use Oak\Console\Command\Command; | ||
use Oak\Console\Command\Signature; | ||
use Oak\Contracts\Console\InputInterface; | ||
use Oak\Contracts\Console\OutputInterface; | ||
use Oak\Contracts\Container\ContainerInterface; | ||
use Oak\Contracts\Scheduler\SchedulerInterface; | ||
|
||
class SchedulerCommand extends Command | ||
{ | ||
/** | ||
* @var SchedulerInterface $scheduler | ||
*/ | ||
private $scheduler; | ||
|
||
/** | ||
* SchedulerCommand constructor. | ||
* @param SchedulerInterface $scheduler | ||
* @param ContainerInterface $app | ||
*/ | ||
public function __construct(SchedulerInterface $scheduler, ContainerInterface $app) | ||
{ | ||
$this->scheduler = $scheduler; | ||
|
||
parent::__construct($app); | ||
} | ||
|
||
/** | ||
* @param Signature $signature | ||
* @return Signature | ||
*/ | ||
protected function createSignature(Signature $signature): Signature | ||
{ | ||
return $signature | ||
->setName('scheduler') | ||
->addSubCommand(TickCommand::class) | ||
; | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->scheduler->runSchedule($output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Oak\Scheduler\Console; | ||
|
||
use Oak\Console\Command\Command; | ||
use Oak\Console\Command\Signature; | ||
use Oak\Contracts\Console\InputInterface; | ||
use Oak\Contracts\Console\OutputInterface; | ||
use Oak\Contracts\Container\ContainerInterface; | ||
use Oak\Contracts\Scheduler\SchedulerInterface; | ||
|
||
class TickCommand extends Command | ||
{ | ||
/** | ||
* @var SchedulerInterface $scheduler | ||
*/ | ||
private $scheduler; | ||
|
||
/** | ||
* SchedulerCommand constructor. | ||
* @param SchedulerInterface $scheduler | ||
* @param ContainerInterface $app | ||
*/ | ||
public function __construct(SchedulerInterface $scheduler, ContainerInterface $app) | ||
{ | ||
$this->scheduler = $scheduler; | ||
|
||
parent::__construct($app); | ||
} | ||
|
||
/** | ||
* @param Signature $signature | ||
* @return Signature | ||
*/ | ||
protected function createSignature(Signature $signature): Signature | ||
{ | ||
return $signature | ||
->setName('tick') | ||
; | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
while (true) { | ||
$this->scheduler->runSchedule($output); | ||
sleep(60); | ||
} | ||
} | ||
} |
Oops, something went wrong.