Skip to content

Commit 9ec2918

Browse files
committed
Refactoring
1 parent 29bffc3 commit 9ec2918

File tree

5 files changed

+489
-142
lines changed

5 files changed

+489
-142
lines changed

README.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# Scheduler [![Latest Version](https://img.shields.io/github/release/azurre/scheduler.svg?style=flat-square)](https://github.com/azurre/scheduler/releases)
1+
# PHP Cron Scheduler [![Latest Version](https://img.shields.io/github/release/azurre/php-cron-scheduler.svg?style=flat-square)](https://github.com/azurre/php-cron-scheduler/releases)
2+
23
Simple cron jobs manager. Keep your project cron jobs in your project!
34

45
# Installation
56

6-
Install composer in your project:
7-
```
8-
curl -s https://getcomposer.org/installer | php
9-
```
10-
117
Require the package with composer:
8+
129
```
13-
composer require azurre/php-scheduler
10+
composer require azurre/php-cron-scheduler
1411
```
1512

1613
# Usage
1714

1815
Add scheduler starter to cron:
16+
1917
```bash
2018
$ crontab -e
2119
```
@@ -25,32 +23,46 @@ $ crontab -e
2523
```
2624

2725
Sample of scheduler.php
26+
2827
```php
2928
$loader = require_once __DIR__ . '/vendor/autoload.php';
3029

3130
use Azurre\Component\Cron\Scheduler;
31+
use Azurre\Component\Cron\Expression;
3232

33-
$php = '/usr/bin/php';
34-
$path = dirname(__FILE__) . '/';
33+
$e = new Expression();
3534

36-
$Scheduler = new Scheduler();
37-
$Scheduler
38-
->setJobPath($path)
39-
->setLogsPath($path);
35+
echo $e->monthly(28); // 0 0 28 * *
36+
echo $e->weekly($e::FRIDAY)->at('05:30'); // 30 5 * * 5
37+
echo $e->daily('06:10'); // 10 6 * * *
4038

41-
$Scheduler->addJob('* * * * *', function($logsPath){
42-
// just do something
43-
file_put_contents($logsPath . 'log.log', 'OK', FILE_APPEND);
44-
});
39+
echo Expression::create() // */5 0 16 1 5
40+
->setMinute('*/5')
41+
->setHour('*')
42+
->setDayOfMonth(16)
43+
->setDayOfWeek('fri')
44+
->setMonth('Jan');
4545

46-
$Scheduler->addJob('*/2 * * * *', function ($logsPath, $jobPath) use ($php) {
47-
// run standalone php script
48-
$cmd = "{$php} {$jobPath}calculate.php >> {$logsPath}calculate.log 2>&1";
49-
$result = `$cmd`;
50-
});
46+
// ------------
5147

52-
// Do something ...
48+
$testFunc = function () {
49+
echo 'TEST OK';
50+
};
51+
$scheduler = new Scheduler();
52+
$scheduler
53+
->addJob('* * * * *', function() {
54+
// just do something
55+
})->addJob('0 0 * * * *', $testFunc);
56+
$scheduler->run();
5357

54-
echo date('d-m-Y H:i:s') . ' Run scheduler...' . PHP_EOL;
55-
$Scheduler->run();
58+
// -----------
59+
60+
$logPath = '/path/to/log.log';
61+
$scheduler = new Scheduler('2021-07-05 06:10:00');
62+
$scheduler->addJob($e, function () use($logPath) {
63+
// run standalone php script
64+
$cmd = "/usr/bin/php /path/to/script.php >> {$logPath} 2>&1";
65+
system($cmd);
66+
});
67+
$scheduler->run();
5668
```

composer.json

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
{
2-
"name": "azurre/php-scheduler",
3-
"description": "Cron jobs manager",
4-
"keywords": ["cron"],
5-
"authors": [
6-
{
7-
"name": "Aleksandr Milenin",
8-
"email": "[email protected]"
9-
}
10-
],
11-
"require": {
12-
"yalesov/cron-expr-parser": "2.*"
13-
},
14-
"autoload": {
15-
"psr-0": {
16-
"Azurre\\Component\\Cron": "src/"
17-
}
18-
},
19-
"license": "GPL-3.0",
20-
"homepage": "https://github.com/azurre/scheduler",
21-
"support": {
22-
"issues": "https://github.com/azurre/scheduler/issues"
23-
}
24-
}
1+
{
2+
"version": "1.2",
3+
"name": "azurre/php-cron-scheduler",
4+
"description": "Cron jobs manager",
5+
"keywords": ["cron","scheduler"],
6+
"authors": [
7+
{
8+
"name": "Aleksandr Milenin",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Azurre\\Component\\Cron\\": "src/"
15+
}
16+
},
17+
"license": "MIT",
18+
"homepage": "https://github.com/azurre/scheduler",
19+
"support": {
20+
"issues": "https://github.com/azurre/scheduler/issues"
21+
}
22+
}

src/Azurre/Component/Cron/Scheduler.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)