Repository: spatie/laravel-cronless-schedule Branch: main Commit: 1a61e3f724af Files: 18 Total size: 17.3 KB Directory structure: gitextract_i8g8mewl/ ├── .editorconfig ├── .gitattributes ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ └── config.yml │ └── workflows/ │ ├── php-cs-fixer.yml │ ├── run-tests.yml │ └── update-changelog.yml ├── .gitignore ├── .php_cs.dist.php ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src/ │ ├── Commands/ │ │ └── ScheduleRunCronlessCommand.php │ └── CronlessScheduleServiceProvider.php └── tests/ ├── ScheduleRunCronlessCommandTest.php └── TestCase.php ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ ; This file is for unifying the coding style for different editors and IDEs. ; More information at https://editorconfig.org root = true [*] charset = utf-8 indent_size = 4 indent_style = space end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false [*.yml] indent_size = 2 ================================================ FILE: .gitattributes ================================================ # Path-based git attributes # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml.dist export-ignore /tests export-ignore /.editorconfig export-ignore /.php.cs export-ignore /.github export-ignore ================================================ FILE: .github/FUNDING.yml ================================================ github: spatie custom: https://spatie.be/open-source/support-us ================================================ FILE: .github/ISSUE_TEMPLATE/config.yml ================================================ blank_issues_enabled: true contact_links: - name: Feature Request url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=ideas about: Share ideas for new features - name: Ask a Question url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=q-a about: Ask the community for help ================================================ FILE: .github/workflows/php-cs-fixer.yml ================================================ name: Check & fix styling on: [push] jobs: php-cs-fixer: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} - name: Run PHP CS Fixer uses: docker://oskarstark/php-cs-fixer-ga with: args: --config=.php_cs.dist.php --allow-risky=yes - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: Fix styling ================================================ FILE: .github/workflows/run-tests.yml ================================================ name: Tests on: - push - pull_request jobs: test: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest] php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*'] dependency-version: [prefer-stable] include: - laravel: 10.* testbench: 8.* - laravel: 9.* testbench: 7.* - laravel: 8.* testbench: 6.* - laravel: 11.* testbench: 9.* - laravel: 12.* testbench: 10.* - laravel: 13.* testbench: 11.* exclude: - laravel: 10.* php: 8.0 - laravel: 10.* php: 7.4 - laravel: 9.* php: 7.4 - laravel: 11.* php: 7.4 - laravel: 11.* php: 8.0 - laravel: 11.* php: 8.1 - laravel: 12.* php: 7.4 - laravel: 12.* php: 8.0 - laravel: 12.* php: 8.1 - laravel: 13.* php: '7.4' - laravel: 13.* php: '8.0' - laravel: 13.* php: '8.1' - laravel: 13.* php: '8.2' name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick coverage: none - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/pest ================================================ FILE: .github/workflows/update-changelog.yml ================================================ name: "Update Changelog" on: release: types: [released] jobs: update: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 with: ref: main - name: Update Changelog uses: stefanzweifel/changelog-updater-action@v1 with: latest-version: ${{ github.event.release.name }} release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG uses: stefanzweifel/git-auto-commit-action@v4 with: branch: main commit_message: Update CHANGELOG file_pattern: CHANGELOG.md ================================================ FILE: .gitignore ================================================ build composer.lock docs vendor coverage .phpunit.result.cache .idea .php-cs-fixer.cache ================================================ FILE: .php_cs.dist.php ================================================ in([ __DIR__ . '/src', __DIR__ . '/tests', ]) ->name('*.php') ->notName('*.blade.php') ->ignoreDotFiles(true) ->ignoreVCS(true); return (new PhpCsFixer\Config()) ->setRules([ '@PSR12' => true, 'array_syntax' => ['syntax' => 'short'], 'ordered_imports' => ['sort_algorithm' => 'alpha'], 'no_unused_imports' => true, 'not_operator_with_successor_space' => true, 'trailing_comma_in_multiline' => true, 'phpdoc_scalar' => true, 'unary_operator_spaces' => true, 'binary_operator_spaces' => true, 'blank_line_before_statement' => [ 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], ], 'phpdoc_single_line_var_spacing' => true, 'phpdoc_var_without_name' => true, 'class_attributes_separation' => [ 'elements' => [ 'method' => 'one', ], ], 'method_argument_space' => [ 'on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => true, ], 'single_trait_insert_per_statement' => true, ]) ->setFinder($finder); ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to `laravel-cronless-schedule` will be documented in this file ## 1.2.1 - 2025-02-17 ### What's Changed * Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/15 **Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.2.0...1.2.1 ## 1.2.0 - 2024-03-02 ### What's Changed * Convert all tests to Pest by @alexmanase in https://github.com/spatie/laravel-cronless-schedule/pull/13 * Laravel 11.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/14 ### New Contributors * @alexmanase made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/13 **Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.1...1.2.0 ## 1.1.1 - 2023-01-24 ### What's Changed - Laravel 10.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/12 ### New Contributors - @laravel-shift made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/12 **Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.0...1.1.1 ## 1.1.0 - 2022-01-19 - support Laravel 9 ## 1.0.2 - 2021-01-20 - allow PHP 8 ## 1.0.1 - 2020-09-08 - add support for Laravel 8 ## 1.0.0 - 2020-06-10 - initial release ================================================ FILE: LICENSE.md ================================================ The MIT License (MIT) Copyright (c) Spatie bvba Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Run the Laravel scheduler without relying on cron [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-cronless-schedule.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-cronless-schedule) ![Tests](https://github.com/spatie/laravel-cronless-schedule/workflows/Tests/badge.svg) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-cronless-schedule.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-cronless-schedule) [Laravel's native scheduler](https://laravel.com/docs/master/scheduling) relies on cron to be executed every minute. It's rock solid and in most cases you should stick to using it. If you want to simulate the scheduler running every minute in a test environment, using cron can be cumbersome. This package provides a command to run the scheduler every minute, without relying on cron. Instead it uses a [ReactPHP](https://reactphp.org) loop. This is how you can start the cronless schedule: ```bash php artisan schedule:run-cronless ``` This command will never end. Behind the scenes it will execute `php artisan schedule` every minute. ## Support us [](https://spatie.be/github-ad-click/laravel-cronless-schedule) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer. Probably you only want to use this schedule in a development environment. ```bash composer require spatie/laravel-cronless-schedule --dev ``` ## Usage This is how you can start the cronless schedule: ```bash php artisan schedule:run-cronless ``` By default, it will run every minute. ### Manually triggering a run To perform an extra run of the scheduler, just press enter. ### Using an alternative frequency If you want to run the scheduler at another frequency, you can pass an amount of seconds to the `frequency` option. Here is an example where the schedule will be run every 5 seconds. ```bash php artisan schedule:run-cronless --frequency=5 ``` ### Using another command If you want to run another command instead of the scheduler, just can pass it to the `command` option. Here is an example where another command will be run every 5 seconds. ```bash php artisan schedule:run-cronless --command=your-favorite-artisan-command ``` ### Only run the schedule for a certain period By default, the command will run forever. You can shorten that period by passing an amount of seconds to the `stop-after-seconds` option. In this example we'll stop the command after 5 seconds ```bash php artisan schedule:run-cronless --stop-after-seconds=5 ``` ## Testing ``` bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. ================================================ FILE: composer.json ================================================ { "name": "spatie/laravel-cronless-schedule", "description": "Run the Laravel scheduler without relying on cron", "keywords": [ "spatie", "laravel-cronless-schedule" ], "homepage": "https://github.com/spatie/laravel-cronless-schedule", "license": "MIT", "authors": [ { "name": "Freek Van der Herten", "email": "freek@spatie.be", "homepage": "https://spatie.be", "role": "Developer" } ], "require": { "php": "^7.4|^8.0", "clue/stdio-react": "^2.3", "illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0|^13.0", "react/event-loop": "^1.1.1" }, "require-dev": { "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", "pestphp/pest": "^1.22|^2.34|^3.7|^4.4" }, "autoload": { "psr-4": { "Spatie\\CronlessSchedule\\": "src" } }, "autoload-dev": { "psr-4": { "Spatie\\CronlessSchedule\\Tests\\": "tests" } }, "scripts": { "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage-html coverage", "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" }, "config": { "sort-packages": true, "allow-plugins": { "pestphp/pest-plugin": true } }, "extra": { "laravel": { "providers": [ "Spatie\\CronlessSchedule\\CronlessScheduleServiceProvider" ] } }, "minimum-stability": "dev", "prefer-stable": true } ================================================ FILE: phpunit.xml.dist ================================================ tests src/ ================================================ FILE: src/Commands/ScheduleRunCronlessCommand.php ================================================ loop = $loop; parent::__construct(); } public function handle() { $this->frequency = (int)$this->option('frequency'); $this->command = (string)$this->option('command'); $this ->outputHeader() ->scheduleCommand() ->registerKeypressHandler() ->runCronlessCommand(); $this->loop->run(); } protected function outputHeader(): self { $this->comment("Will execute {$this->command} every {$this->frequency} seconds..."); $this->comment("Press enter to manually invoke a run..."); $this->comment('-------------------------------------------------------'); $this->comment(''); return $this; } protected function scheduleCommand(): self { $stopAfter = (int)$this->option('stop-after-seconds'); if ($stopAfter > 0) { $this->loop->addTimer($stopAfter, fn () => $this->loop->stop()); } $this->loop->addPeriodicTimer($this->frequency, fn () => $this->runCronlessCommand()); return $this; } protected function registerKeypressHandler(): self { $stdio = new Stdio($this->loop); $stdio->setEcho(false); $stdio->on('data', fn () => $this->runCronlessCommand()); return $this; } protected function runCronlessCommand() { $this->comment($this->timestamp("Running {$this->command}...")); $this->call($this->command); $this->comment($this->timestamp("{$this->command} finished.")); $this->comment(''); } protected function timestamp(string $message): string { $currentTime = now()->format('Y-m-d H:i:s'); return "[{$currentTime}] - {$message}"; } } ================================================ FILE: src/CronlessScheduleServiceProvider.php ================================================ app ->when(ScheduleRunCronlessCommand::class) ->needs(LoopInterface::class) ->give(fn () => Factory::create()); } public function boot() { $this->commands([ ScheduleRunCronlessCommand::class, ]); } } ================================================ FILE: tests/ScheduleRunCronlessCommandTest.php ================================================ artisan('schedule:run-cronless --stop-after-seconds=1') ->assertExitCode(0); ================================================ FILE: tests/TestCase.php ================================================