Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Fixed error in running jobs with arguments of type function (test created to validate)
  • Loading branch information
robersonfaria committed Mar 2, 2022
1 parent dd04cee commit a4433d3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 23 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Arguments fix: details in [pull request](https://github.com/robersonfaria/laravel-database-schedule/pull/51)

## [1.3.1] - 2022-03-02

### Changed

- Update README.md

### Fixed

- Fixed error in running jobs with arguments of type function (test created to validate)
42 changes: 28 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ protected function gate()
}
```

#### Groups:

If you have a lot of jobs, you can make managing them easier by enabling the groups feature in `config/database-schedule.php`:

```php
/**
* If you have a lot of jobs, you can group them for easier managing of jobs.
*/
'enable_groups' => true,
```

#### Examples:

If you want to limit access to a route to users who have a certain role, you can do so.
Expand All @@ -90,6 +79,19 @@ Gate::define('viewDatabaseSchedule', function ($user) {

Basically, if your gate has `return true` access will be allowed, if `return false` access will be restricted.


#### Groups:

If you have a lot of jobs, you can make managing them easier by enabling the groups feature in `config/database-schedule.php`:

```php
/**
* If you have a lot of jobs, you can group them for easier managing of jobs.
*/
'enable_groups' => true,
```
This will allow you to filter in the job listing only the jobs belonging to a certain group.

### Scheduled Task Example

Create the command for your scheduled task `app/Console/Commands/test.php`:
Expand Down Expand Up @@ -152,16 +154,28 @@ php artisan schedule:run

The console output will look like this
```bash
Running scheduled command: '/usr/bin/php7.2' 'artisan' command:test '1' '2021-02-10 00:00:00' '2021-04-10 00:00:00' > 'path/to/storage/logs/schedule-dcccb62f29f754dc83a86a3d0b59afb00a08fdb3.log' 2>&1
Running scheduled command: ('/usr/bin/php7.4' 'artisan' command:test 1 '2022-02-02 00:00:00' '2022-04-02 00:00:00' > 'path/to/storage/logs/schedule-8763d2ce5a20ee888dd9d8a7e5a5cfcd4b315375.log' 2>&1 ;
```
If you marked the sending of the output by email you will receive an email similar to this one:
![Mail Output](docs/mail-output.png)
## Known issues:
## Schedule List
You can also list registered and active commands using artisan command:
```bash
$ php artisan schedule:list

+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+
| Command | Interval | Description | Next Due |
+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+
| '/usr/bin/php7.4' 'artisan' inspire | * * * * * | | 2022-03-02 17:05:00 +00:00 |
| '/usr/bin/php7.4' 'artisan' command:test 1 '2022-02-02 00:00:00' '2022-04-02 00:00:00' | * * * * * | | 2022-03-02 17:05:00 +00:00 |
+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+
```
* Does not record run history when runInBackground is used
## CHANGELOG
Expand Down
Binary file modified docs/list-schedule1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/new-schedule2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/show-history1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
<directory suffix="Test.php">tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<include>
<directory suffix=".php">./tests</directory>
</include>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getArguments(): array
continue;
}
if (isset($value["type"]) && $value['type'] === 'function') {
$arguments[$argument] = (string)$value['value']();
eval('$arguments[$argument] = (string) ' .$value['value']);
} else {
$arguments[$argument] = $value['value'];
}
Expand Down
38 changes: 38 additions & 0 deletions tests/Feature/ScheduleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,42 @@ function (\Illuminate\Console\Scheduling\Event $event) use ($task) {
}
);
}

public function testCommandWithFunctionTypeArgument()
{
$task = factory(Schedule::class)
->create([
'command' => 'phpunit:test',
'params' => [
'argument' => [
'value' => '\Carbon\Carbon::now()->format("Y/m/d");',
'type' => 'function'
]
]
]);
/** @var \Illuminate\Console\Scheduling\Schedule $schedule */
$schedule = app()->make(\Illuminate\Console\Scheduling\Schedule::class);

$events = collect($schedule->events())
->filter(
function (\Illuminate\Console\Scheduling\Event $event) use ($task) {
return stripos($event->command, $task->command);
}
);

if ($events->count() == 0) {
$this->fail('No events found');
}

$events->each(
function (\Illuminate\Console\Scheduling\Event $event) use ($task) {
// This example is for hourly commands.
$this->assertEquals($task->expression, $event->expression);
$this->assertStringEndsWith(
"phpunit:test '" . now()->format("Y/m/d") . "'",
$event->command
);
}
);
}
}

0 comments on commit a4433d3

Please sign in to comment.