[
  {
    "path": ".editorconfig",
    "content": "; This file is for unifying the coding style for different editors and IDEs.\n; More information at https://editorconfig.org\n\nroot = true\n\n[*]\ncharset = utf-8\nindent_size = 4\nindent_style = space\nend_of_line = lf\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n[*.md]\ntrim_trailing_whitespace = false\n\n[*.yml]\nindent_size = 2\n"
  },
  {
    "path": ".gitattributes",
    "content": "# Path-based git attributes\n# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html\n\n# Ignore all test and documentation with \"export-ignore\".\n/.gitattributes     export-ignore\n/.gitignore         export-ignore\n/.travis.yml        export-ignore\n/phpunit.xml.dist   export-ignore\n/tests              export-ignore\n/.editorconfig      export-ignore\n/.php.cs            export-ignore\n/.github            export-ignore\n\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "github: spatie\ncustom: https://spatie.be/open-source/support-us\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: true\ncontact_links:\n    - name: Feature Request\n      url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=ideas\n      about: Share ideas for new features\n    - name: Ask a Question\n      url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=q-a\n      about: Ask the community for help\n"
  },
  {
    "path": ".github/workflows/php-cs-fixer.yml",
    "content": "name: Check & fix styling\n\non: [push]\n\njobs:\n  php-cs-fixer:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n        with:\n          ref: ${{ github.head_ref }}\n\n      - name: Run PHP CS Fixer\n        uses: docker://oskarstark/php-cs-fixer-ga\n        with:\n          args: --config=.php_cs.dist.php --allow-risky=yes\n\n      - name: Commit changes\n        uses: stefanzweifel/git-auto-commit-action@v4\n        with:\n          commit_message: Fix styling\n"
  },
  {
    "path": ".github/workflows/run-tests.yml",
    "content": "name: Tests\n\non:\n  - push\n  - pull_request\n\njobs:\n  test:\n    runs-on: ${{ matrix.os }}\n\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest]\n        php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']\n        laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*']\n        dependency-version: [prefer-stable]\n        include:\n          - laravel: 10.*\n            testbench: 8.*\n          - laravel: 9.*\n            testbench: 7.*\n          - laravel: 8.*\n            testbench: 6.*\n          - laravel: 11.*\n            testbench: 9.*\n          - laravel: 12.*\n            testbench: 10.*\n          - laravel: 13.*\n            testbench: 11.*\n        exclude:\n          - laravel: 10.*\n            php: 8.0\n          - laravel: 10.*\n            php: 7.4\n          - laravel: 9.*\n            php: 7.4\n          - laravel: 11.*\n            php: 7.4\n          - laravel: 11.*\n            php: 8.0\n          - laravel: 11.*\n            php: 8.1\n          - laravel: 12.*\n            php: 7.4\n          - laravel: 12.*\n            php: 8.0\n          - laravel: 12.*\n            php: 8.1\n          - laravel: 13.*\n            php: '7.4'\n          - laravel: 13.*\n            php: '8.0'\n          - laravel: 13.*\n            php: '8.1'\n          - laravel: 13.*\n            php: '8.2'\n\n    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n\n      - name: Setup PHP\n        uses: shivammathur/setup-php@v2\n        with:\n          php-version: ${{ matrix.php }}\n          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick\n          coverage: none\n\n      - name: Install dependencies\n        run: |\n          composer require \"laravel/framework:${{ matrix.laravel }}\" \"orchestra/testbench:${{ matrix.testbench }}\" --no-interaction --no-update\n          composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction\n\n      - name: Execute tests\n        run: vendor/bin/pest\n"
  },
  {
    "path": ".github/workflows/update-changelog.yml",
    "content": "name: \"Update Changelog\"\n\non:\n  release:\n    types: [released]\n\njobs:\n  update:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v2\n        with:\n          ref: main\n\n      - name: Update Changelog\n        uses: stefanzweifel/changelog-updater-action@v1\n        with:\n          latest-version: ${{ github.event.release.name }}\n          release-notes: ${{ github.event.release.body }}\n\n      - name: Commit updated CHANGELOG\n        uses: stefanzweifel/git-auto-commit-action@v4\n        with:\n          branch: main\n          commit_message: Update CHANGELOG\n          file_pattern: CHANGELOG.md\n"
  },
  {
    "path": ".gitignore",
    "content": "build\ncomposer.lock\ndocs\nvendor\ncoverage\n.phpunit.result.cache\n.idea\n.php-cs-fixer.cache\n\n\n"
  },
  {
    "path": ".php_cs.dist.php",
    "content": "<?php\n\n$finder = Symfony\\Component\\Finder\\Finder::create()\n    ->in([\n        __DIR__ . '/src',\n        __DIR__ . '/tests',\n    ])\n    ->name('*.php')\n    ->notName('*.blade.php')\n    ->ignoreDotFiles(true)\n    ->ignoreVCS(true);\n\nreturn (new PhpCsFixer\\Config())\n    ->setRules([\n        '@PSR12' => true,\n        'array_syntax' => ['syntax' => 'short'],\n        'ordered_imports' => ['sort_algorithm' => 'alpha'],\n        'no_unused_imports' => true,\n        'not_operator_with_successor_space' => true,\n        'trailing_comma_in_multiline' => true,\n        'phpdoc_scalar' => true,\n        'unary_operator_spaces' => true,\n        'binary_operator_spaces' => true,\n        'blank_line_before_statement' => [\n            'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],\n        ],\n        'phpdoc_single_line_var_spacing' => true,\n        'phpdoc_var_without_name' => true,\n        'class_attributes_separation' => [\n            'elements' => [\n                'method' => 'one',\n            ],\n        ],\n        'method_argument_space' => [\n            'on_multiline' => 'ensure_fully_multiline',\n            'keep_multiple_spaces_after_comma' => true,\n        ],\n        'single_trait_insert_per_statement' => true,\n    ])\n    ->setFinder($finder);\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\nAll notable changes to `laravel-cronless-schedule` will be documented in this file\n\n## 1.2.1 - 2025-02-17\n\n### What's Changed\n\n* Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/15\n\n**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.2.0...1.2.1\n\n## 1.2.0 - 2024-03-02\n\n### What's Changed\n\n* Convert all tests to Pest by @alexmanase in https://github.com/spatie/laravel-cronless-schedule/pull/13\n* Laravel 11.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/14\n\n### New Contributors\n\n* @alexmanase made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/13\n\n**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.1...1.2.0\n\n## 1.1.1 - 2023-01-24\n\n### What's Changed\n\n- Laravel 10.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/12\n\n### New Contributors\n\n- @laravel-shift made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/12\n\n**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.0...1.1.1\n\n## 1.1.0 - 2022-01-19\n\n- support Laravel 9\n\n## 1.0.2 - 2021-01-20\n\n- allow PHP 8\n\n## 1.0.1 - 2020-09-08\n\n- add support for Laravel 8\n\n## 1.0.0 - 2020-06-10\n\n- initial release\n"
  },
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n\nCopyright (c) Spatie bvba <info@spatie.be>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# Run the Laravel scheduler without relying on cron\n\n[![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)\n![Tests](https://github.com/spatie/laravel-cronless-schedule/workflows/Tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-cronless-schedule.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-cronless-schedule)\n\n[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.\n\nIf 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.\n\nThis is how you can start the cronless schedule:\n\n```bash\nphp artisan schedule:run-cronless\n```\n\nThis command will never end. Behind the scenes it will execute `php artisan schedule` every minute. \n \n## Support us\n\n[<img src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-cronless-schedule.jpg?t=1\" width=\"419px\" />](https://spatie.be/github-ad-click/laravel-cronless-schedule)\n\nWe 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).\n\nWe 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).\n\n## Installation\n\nYou can install the package via composer. Probably you only want to use this schedule in a development environment.\n\n```bash\ncomposer require spatie/laravel-cronless-schedule --dev\n```\n\n## Usage\n\nThis is how you can start the cronless schedule:\n\n```bash\nphp artisan schedule:run-cronless\n```\n\nBy default, it will run every minute. \n\n### Manually triggering a run\n\nTo perform an extra run of the scheduler, just press enter.\n\n### Using an alternative frequency\n\nIf 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.\n\n```bash\nphp artisan schedule:run-cronless --frequency=5\n```\n\n### Using another command\n\nIf 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.\n\n```bash\nphp artisan schedule:run-cronless --command=your-favorite-artisan-command\n```\n\n### Only run the schedule for a certain period\n\nBy default, the command will run forever. You can shorten that period by passing an amount of seconds to the `stop-after-seconds` option.\n\nIn this example we'll stop the command after 5 seconds\n\n```bash\nphp artisan schedule:run-cronless --stop-after-seconds=5\n```\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"spatie/laravel-cronless-schedule\",\n    \"description\": \"Run the Laravel scheduler without relying on cron\",\n    \"keywords\": [\n        \"spatie\",\n        \"laravel-cronless-schedule\"\n    ],\n    \"homepage\": \"https://github.com/spatie/laravel-cronless-schedule\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Freek Van der Herten\",\n            \"email\": \"freek@spatie.be\",\n            \"homepage\": \"https://spatie.be\",\n            \"role\": \"Developer\"\n        }\n    ],\n    \"require\": {\n        \"php\": \"^7.4|^8.0\",\n        \"clue/stdio-react\": \"^2.3\",\n        \"illuminate/support\": \"^8.0|^9.0|^10.0|^11.0|^12.0|^13.0\",\n        \"react/event-loop\": \"^1.1.1\"\n    },\n    \"require-dev\": {\n        \"orchestra/testbench\": \"^6.0|^7.0|^8.0|^9.0|^10.0|^11.0\",\n        \"pestphp/pest\": \"^1.22|^2.34|^3.7|^4.4\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Spatie\\\\CronlessSchedule\\\\\": \"src\"\n        }\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Spatie\\\\CronlessSchedule\\\\Tests\\\\\": \"tests\"\n        }\n    },\n    \"scripts\": {\n        \"test\": \"vendor/bin/pest\",\n        \"test-coverage\": \"vendor/bin/pest --coverage-html coverage\",\n        \"format\": \"vendor/bin/php-cs-fixer fix --allow-risky=yes\"\n    },\n    \"config\": {\n        \"sort-packages\": true,\n        \"allow-plugins\": {\n            \"pestphp/pest-plugin\": true\n        }\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Spatie\\\\CronlessSchedule\\\\CronlessScheduleServiceProvider\"\n            ]\n        }\n    },\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true\n}\n"
  },
  {
    "path": "phpunit.xml.dist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"vendor/phpunit/phpunit/phpunit.xsd\"\n         bootstrap=\"vendor/autoload.php\"\n         colors=\"true\"\n>\n  <testsuites>\n    <testsuite name=\"Spatie Test Suite\">\n      <directory>tests</directory>\n    </testsuite>\n  </testsuites>\n  <source>\n    <include>\n      <directory suffix=\".php\">src/</directory>\n    </include>\n  </source>\n</phpunit>\n"
  },
  {
    "path": "src/Commands/ScheduleRunCronlessCommand.php",
    "content": "<?php\n\nnamespace Spatie\\CronlessSchedule\\Commands;\n\nuse Clue\\React\\Stdio\\Stdio;\nuse Illuminate\\Console\\Command;\nuse React\\EventLoop\\LoopInterface;\n\nclass ScheduleRunCronlessCommand extends Command\n{\n    public $signature = 'schedule:run-cronless\n                            {--frequency=60}\n                            {--command=schedule:run}\n                            {--stop-after-seconds=0}\n    ';\n\n    public $description = 'Run the scheduler';\n\n    protected ?string $command = null;\n\n    protected ?int $frequency = null;\n\n    protected LoopInterface $loop;\n\n    public function __construct(LoopInterface $loop)\n    {\n        $this->loop = $loop;\n\n        parent::__construct();\n    }\n\n    public function handle()\n    {\n        $this->frequency = (int)$this->option('frequency');\n        $this->command = (string)$this->option('command');\n\n        $this\n            ->outputHeader()\n            ->scheduleCommand()\n            ->registerKeypressHandler()\n            ->runCronlessCommand();\n\n        $this->loop->run();\n    }\n\n    protected function outputHeader(): self\n    {\n        $this->comment(\"Will execute {$this->command} every {$this->frequency} seconds...\");\n        $this->comment(\"Press enter to manually invoke a run...\");\n        $this->comment('-------------------------------------------------------');\n        $this->comment('');\n\n        return $this;\n    }\n\n    protected function scheduleCommand(): self\n    {\n        $stopAfter = (int)$this->option('stop-after-seconds');\n\n        if ($stopAfter > 0) {\n            $this->loop->addTimer($stopAfter, fn () => $this->loop->stop());\n        }\n\n        $this->loop->addPeriodicTimer($this->frequency, fn () => $this->runCronlessCommand());\n\n        return $this;\n    }\n\n    protected function registerKeypressHandler(): self\n    {\n        $stdio = new Stdio($this->loop);\n\n        $stdio->setEcho(false);\n\n        $stdio->on('data', fn () => $this->runCronlessCommand());\n\n        return $this;\n    }\n\n    protected function runCronlessCommand()\n    {\n        $this->comment($this->timestamp(\"Running {$this->command}...\"));\n\n        $this->call($this->command);\n\n        $this->comment($this->timestamp(\"{$this->command} finished.\"));\n        $this->comment('');\n    }\n\n    protected function timestamp(string $message): string\n    {\n        $currentTime = now()->format('Y-m-d H:i:s');\n\n        return \"[{$currentTime}] - {$message}\";\n    }\n}\n"
  },
  {
    "path": "src/CronlessScheduleServiceProvider.php",
    "content": "<?php\n\nnamespace Spatie\\CronlessSchedule;\n\nuse Illuminate\\Support\\ServiceProvider;\nuse React\\EventLoop\\Factory;\nuse React\\EventLoop\\LoopInterface;\nuse Spatie\\CronlessSchedule\\Commands\\ScheduleRunCronlessCommand;\n\nclass CronlessScheduleServiceProvider extends ServiceProvider\n{\n    public function register()\n    {\n        $this->app\n            ->when(ScheduleRunCronlessCommand::class)\n            ->needs(LoopInterface::class)\n            ->give(fn () => Factory::create());\n    }\n\n    public function boot()\n    {\n        $this->commands([\n            ScheduleRunCronlessCommand::class,\n        ]);\n    }\n}\n"
  },
  {
    "path": "tests/ScheduleRunCronlessCommandTest.php",
    "content": "<?php\n\nuses(Spatie\\CronlessSchedule\\Tests\\TestCase::class);\n\nit('can run the loop without cron')\n    ->artisan('schedule:run-cronless --stop-after-seconds=1')\n    ->assertExitCode(0);\n"
  },
  {
    "path": "tests/TestCase.php",
    "content": "<?php\n\nnamespace Spatie\\CronlessSchedule\\Tests;\n\nuse Orchestra\\Testbench\\TestCase as Orchestra;\nuse Spatie\\CronlessSchedule\\CronlessScheduleServiceProvider;\n\nclass TestCase extends Orchestra\n{\n    protected function getPackageProviders($app)\n    {\n        return [\n            CronlessScheduleServiceProvider::class,\n        ];\n    }\n}\n"
  }
]