-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* base functionalities * tests
- Loading branch information
Showing
43 changed files
with
1,294 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
## Purpose and approach | ||
|
||
- Describe the problem or feature in addition to a link to the issues. |
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 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: ~ | ||
|
||
jobs: | ||
build: | ||
name: Test Suite | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP, with composer and extensions | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.0 | ||
extensions: mbstring, xml, hash, ctype, iconv, curl | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache composer dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: composer-${{ hashFiles('composer.lock') }} | ||
restore-keys: composer- | ||
|
||
- name: Install Composer dependencies | ||
run: composer install -n | ||
|
||
- uses: symfonycorp/security-checker-action@v4 | ||
|
||
- name: Validate composer.lock | ||
run: composer validate --strict | ||
|
||
- name: Run pint | ||
run: vendor/bin/pint --test | ||
|
||
- name: Run pest | ||
run: vendor/bin/pest | ||
|
||
- name: Run Phpstan | ||
run: vendor/bin/phpstan --no-progress --debug --memory-limit=1G |
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,10 @@ | ||
/.phpunit.cache | ||
/vendor | ||
.phpunit.result.cache | ||
/.fleet | ||
/.idea | ||
/.vscode | ||
/.phpstorm.meta.php | ||
clover.xml | ||
/build | ||
composer.lock |
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,75 @@ | ||
# Laravel Schedule Police | ||
[![Latest Stable Version](https://poser.pugx.org/acdphp/laravel-schedule-police/v)](https://packagist.org/packages/acdphp/laravel-schedule-police) | ||
|
||
Use this if you need to: | ||
- :white_check_mark: Stop and start scheduled commands without redeploying. | ||
- :white_check_mark: Execute commands without going into server console. | ||
- :white_check_mark: Keep the visibility, control, and reviewability of the schedule configurations in your codebase. | ||
|
||
## Installation | ||
1. Install the package | ||
```shell | ||
composer require acdphp/laravel-schedule-police | ||
``` | ||
|
||
2. Run the migration. | ||
```shell | ||
php artisan migrate | ||
``` | ||
|
||
3. Publish assets | ||
```shell | ||
php artisan vendor:publish --tag=schedule-police-assets --force | ||
``` | ||
|
||
4. Update your Console Kernel to extend `Acdphp\SchedulePolice\Console\Kernel` instead of `Illuminate\Foundation\Console\Kernel`. | ||
```php | ||
namespace App\Console; | ||
use Acdphp\SchedulePolice\Console\Kernel as ConsoleKernel; | ||
class Kernel extends ConsoleKernel | ||
... | ||
``` | ||
|
||
## Config | ||
You may override the config by publishing it. | ||
```shell | ||
php artisan vendor:publish --tag=schedule-police-config | ||
``` | ||
|
||
You may also just define environment variables if you don't need to publish the config. | ||
- Disable command execution in the dashboard. | ||
```dotenv | ||
SCHEDULE_POLICE_ALLOW_EXECUTE_CMD=false | ||
``` | ||
- Add prefix to routes. | ||
```dotenv | ||
SCHEDULE_POLICE_URL_PREFIX=your-prefix | ||
``` | ||
## Dashboard | ||
After installation, you may access the dashboard via the `/schedule-police` route. | ||
### Authorization | ||
By default, you will only be able to access this dashboard in the local environment. However, you may specify authorization for non-local environments by defining `viewSchedulePolice` gate, typically within the `boot` method of the `App\Providers\AuthServiceProvider` class. | ||
```php | ||
public function boot(): void | ||
{ | ||
Gate::define('viewSchedulePolice', function (User $user) { | ||
// return true or false | ||
}); | ||
} | ||
``` | ||
## Screenshots | ||
### Events list page | ||
![events page](./.docs/screenshots/screenshot-events-page.png) | ||
### Execute page | ||
![execute page](./.docs/screenshots/screenshot-execute-page.png) | ||
## License | ||
The MIT License (MIT). Please see [License File](LICENSE) for more information. |
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,43 @@ | ||
{ | ||
"name": "acdphp/laravel-schedule-police", | ||
"description": "Stop, start or execute scheduled commands from a simple dashboard without redeploying, while maintaining the visibility, control, and reviewability of the configurations in your codebase.", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Carlo Dinopol", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^8.0" | ||
}, | ||
"require-dev": { | ||
"laravel/pint": "^1.5", | ||
"phpstan/phpstan": "^1.10", | ||
"larastan/larastan": "^2.7", | ||
"ekino/phpstan-banned-code": "^1.0", | ||
"orchestra/testbench": "^7.37", | ||
"pestphp/pest": "^1.23", | ||
"pestphp/pest-plugin-laravel": "^1.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Acdphp\\SchedulePolice\\": "src", | ||
"Acdphp\\SchedulePolice\\Tests\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Acdphp\\SchedulePolice\\SchedulePoliceServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
use Acdphp\SchedulePolice\Http\Middleware\RestrictedAccess; | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| URL prefix | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Use this when you need to add prefix to the routes. | ||
| | ||
*/ | ||
'url_prefix' => env('SCHEDULE_POLICE_URL_PREFIX', ''), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Separate control by frequency | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Determine if similar commands should be controlled separately when | ||
| having different frequency/expression. This will still show separate | ||
| entries in the view list but both will share the control. | ||
| | ||
*/ | ||
'separate_by_frequency' => false, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Enable execution | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Disable command execution from the dashboard. | ||
| | ||
*/ | ||
'enable_execution' => env('SCHEDULE_POLICE_ALLOW_EXECUTE_CMD', true), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Blacklisted commands | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Disable execution of specific commands. | ||
| The commands specified will be the root of comparison, meaning all commands | ||
| that will be executed from the dashboard that starts with it will be prevented. | ||
| | ||
| E.g. 'migrate' will also block 'migrate:fresh', 'migrate --seed', etc. | ||
| | ||
*/ | ||
'blacklisted_commands' => [ | ||
'migrate:fresh', | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Causer key | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Blame. | ||
| | ||
*/ | ||
'causer_key' => 'email', | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sort events by stopped | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When true, stopped events will be sorted to be on top. This is default | ||
| to false since it could be confusing to see events flying around. | ||
| | ||
*/ | ||
'sort_by_stopped' => false, | ||
|
||
'middleware' => [ | ||
'web', | ||
RestrictedAccess::class, | ||
], | ||
]; |
30 changes: 30 additions & 0 deletions
30
database/migrations/2023_12_13_100000_create_stopped_scheduled_events_table.php
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,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('stopped_scheduled_events', static function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('key', 500); | ||
$table->string('expression', 50); | ||
$table->timestamps(); | ||
$table->string('by')->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('stopped_scheduled_events'); | ||
} | ||
}; |
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,35 @@ | ||
includes: | ||
- ./vendor/larastan/larastan/extension.neon | ||
- ./vendor/ekino/phpstan-banned-code/extension.neon | ||
|
||
parameters: | ||
checkModelProperties: true | ||
paths: | ||
- src | ||
level: 6 | ||
checkMissingIterableValueType: false | ||
reportUnmatchedIgnoredErrors: false | ||
checkGenericClassInNonGenericObjectType: false | ||
banned_code: | ||
nodes: | ||
- { type: Stmt_Echo, functions: null } | ||
- { type: Expr_Eval, functions: null } | ||
- { type: Expr_Exit, functions: null } | ||
- { type: Expr_Print, functions: null } | ||
- | ||
type: Expr_FuncCall | ||
functions: | ||
- dd | ||
- ddd | ||
- debug_backtrace | ||
- dump | ||
- exec | ||
- passthru | ||
- phpinfo | ||
- print_r | ||
- proc_open | ||
- shell_exec | ||
- system | ||
- var_dump | ||
use_from_tests: false |
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,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
backupGlobals="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
executionOrder="random" | ||
failOnWarning="true" | ||
failOnRisky="true" | ||
failOnEmptyTestSuite="true" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="Feature"> | ||
<directory>tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
<php> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/> | ||
</php> | ||
</phpunit> |
Oops, something went wrong.