### Manual Installation: Configure Autoloading Source: https://github.com/codeigniter4/tasks/blob/develop/docs/installation.md For manual installation, add the CodeIgniter\Tasks namespace to the \$psr4 array in `app/Config/Autoload.php`, pointing to the package's source directory. ```php APPPATH, 'Config' => APPPATH . 'Config', 'CodeIgniter\Settings' => APPPATH . 'ThirdParty/settings/src', 'CodeIgniter\Tasks' => APPPATH . 'ThirdParty/tasks/src', ]; // ... ``` -------------------------------- ### Install CodeIgniter Tasks via Composer Source: https://github.com/codeigniter4/tasks/blob/develop/docs/index.md Use Composer to add the CodeIgniter Tasks library to your project. This is the initial setup step. ```bash composer require codeigniter4/tasks ``` -------------------------------- ### Server Cronjob Setup Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Configure a cronjob on your server to run the CodeIgniter task runner every minute. Ensure the path to your project and the `spark` executable are correct. ```bash * * * * * cd /path-to-your-project && php spark tasks:run ``` -------------------------------- ### Initialize Task Scheduler in CodeIgniter 4 Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Configure tasks by registering them in the `init()` method of `app/Config/Tasks.php`. This example schedules a closure to refresh demo content every Monday. ```php call(function() { DemoContent::refresh(); })->mondays(); } } ``` -------------------------------- ### Schedule a Queue Job Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedule a queue job using the `queue()` method, specifying the queue name, job name, and any necessary data. This example schedules a job hourly. ```php $schedule->queue('queue-name', 'jobName', ['data' => 'array'])->hourly(); ``` -------------------------------- ### Schedule a Shell Command Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Execute server shell commands using the `shell()` method. This example copies 'foo' to 'bar' daily at 11:00 PM. Note: `exec` access might be disabled on shared servers. ```php $schedule->shell('cp foo bar')->daily()->at('11:00 pm'); ``` -------------------------------- ### Schedule a Task to Run as a Single Instance Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Ensure a task runs only once at a time, even if it takes longer than its scheduled interval, by using the `singleInstance()` method. This example runs a heavy task every minute. ```php $schedule->command('demo:heavy-task')->everyMinute()->singleInstance(); ``` -------------------------------- ### Schedule a Queue Job with Single Instance and TTL Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Set a time-to-live (TTL) for the single instance lock on a queue job. The job must start within the TTL and is renewed upon starting. ```php $schedule->queue('queue-name', 'jobName', ['data' => 'array'])->hourly()->singleInstance(30 * MINUTE); ``` -------------------------------- ### Schedule a URL Call Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Ping a URL regularly using the `url()` method for simple GET requests. For more complex interactions, consider closures or commands. ```php $schedule->url('https://my-status-cloud.com?site=foo.com')->everyFiveMinutes(); ``` -------------------------------- ### Name a Task for Reference Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Assigns a name to a task using the `named()` method, allowing for easier reference, for example, via the CLI. ```php $schedule->command('foo')->nightly()->named('foo-task'); ``` -------------------------------- ### Schedule a Task in CodeIgniter Source: https://github.com/codeigniter4/tasks/blob/develop/docs/index.md Define and schedule tasks within your CodeIgniter application by extending the BaseTasks class and implementing the init method. This example schedules a command to run hourly on weekdays. ```php command('foo')->weekdays()->hourly(); } } ``` -------------------------------- ### Schedule a URL Task Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Schedule a task to access a remote URL via a GET request. Useful for API interactions or cross-server coordination. For more complex calls, consider a command. ```php $schedule->url('https://example.com/api/sync_remote_db')->environments('production')->everyTuesday();); ``` -------------------------------- ### Database Migration for Settings (Unix) Source: https://github.com/codeigniter4/tasks/blob/develop/docs/installation.md Run this command on Unix-based systems to migrate the database and add necessary tables for the Settings module. ```bash php spark migrate -n CodeIgniter\Settings ``` -------------------------------- ### Combine Frequency and Environment Restrictions Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Demonstrates combining multiple frequency options (weekdays, hourly) with environment restrictions for nuanced task scheduling. ```php $schedule->command('foo') ->weekdays() ->hourly() ->environments('development'); ``` -------------------------------- ### Publish Tasks Configuration File Source: https://github.com/codeigniter4/tasks/blob/develop/docs/configuration.md Run this command to publish the Tasks configuration file to app/Config/Tasks.php for customization. This makes the configuration options available for modification. ```bash php spark tasks:publish ``` -------------------------------- ### List Available Tasks Source: https://github.com/codeigniter4/tasks/blob/develop/docs/cli-commands.md Use this command to see all defined tasks, their types, and their next scheduled run times. The output includes a table with task details. ```console php spark tasks:list ``` -------------------------------- ### Run Task Every Five Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every five minutes. ```php $schedule->everyFiveMinutes() ``` -------------------------------- ### Migrate Database for CodeIgniter Settings Source: https://github.com/codeigniter4/tasks/blob/develop/README.md Run database migrations for the CodeIgniter Settings module. Use the appropriate command for your operating system. ```bash php spark migrate -n CodeIgniter\Settings ``` ```bash php spark migrate -n CodeIgniter\Settings ``` -------------------------------- ### Run Task Every Fifteen Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every fifteen minutes. ```php $schedule->everyFifteenMinutes() ``` -------------------------------- ### Run Task Every Thirty Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every thirty minutes. ```php $schedule->everyThirtyMinutes() ``` -------------------------------- ### Initialize Scheduler in Config File Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Define scheduled tasks within the `init()` method of your `Config\\\Tasks.php` file. The `Scheduler` instance is passed to this method. ```php public function init(Scheduler $schedule) { $schedule->command('foo:bar')->nightly(); } ``` -------------------------------- ### Run Task Monthly Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run on the first day of every month. Accepts an optional time string. ```php $schedule->monthly('12:21pm') ``` -------------------------------- ### Run Task Quarterly Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run on the first day of each quarter (Jan 1, Apr 1, July 1, Oct 1). Accepts an optional time string. ```php $schedule->quarterly('5:00am') ``` -------------------------------- ### Run Task on Mondays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Monday. Accepts an optional time string. ```php $schedule->mondays('3:15am') ``` -------------------------------- ### Run Scheduled Tasks Source: https://github.com/codeigniter4/tasks/blob/develop/docs/cli-commands.md This is the main command to execute scheduled tasks. It should typically be run by a cron job every minute. It can also be used to run a single task immediately using the `--task` option. ```console php spark tasks:run ``` ```console php spark tasks:run --task emails ``` -------------------------------- ### Run Task Every N Hours at a Specific Minute Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every specified number of hours, at a particular minute of that hour (e.g., every 3 hours at XX:15). ```php $schedule->everyHour(3, 15) ``` -------------------------------- ### Run Task Every N Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run at a regular interval of every specified number of minutes. ```php $schedule->everyMinute(20) ``` -------------------------------- ### Configure Composer Minimum Stability Source: https://github.com/codeigniter4/tasks/blob/develop/docs/installation.md If you encounter a minimum-stability error with Composer, run these commands to set the stability to 'dev' and prefer stable packages. ```bash composer config minimum-stability dev composer config prefer-stable true ``` -------------------------------- ### Run Task Every N Months Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every specified number of months. ```php $schedule->everyMonth(4) ``` -------------------------------- ### Set Up Cron Job to Run Tasks Source: https://github.com/codeigniter4/tasks/blob/develop/docs/configuration.md This cron job configuration will execute the Tasks runner every minute. Ensure you replace *path-to-your-project* with the actual absolute path to your CodeIgniter project. Output is redirected to /dev/null to prevent unwanted logs. ```cron * * * * * cd /path-to-your-project && php spark tasks:run >> /dev/null 2>&1 ``` -------------------------------- ### Run Task Yearly Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run on the first day of the year. Accepts an optional time string. ```php $schedule->yearly('12:34am') ``` -------------------------------- ### Run Task Daily at a Specific Time Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run once a day. Accepts a time string (e.g., '4:00 am'). Defaults to midnight if no time is provided. ```php $schedule->daily('4:00 am') ``` -------------------------------- ### Run Task on Tuesdays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Tuesday. Accepts an optional time string. ```php $schedule->tuesdays('3:15am') ``` -------------------------------- ### Run Task at Specific Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only at the specified minutes of an hour. ```php $schedule->minutes([0,20,40]) ``` -------------------------------- ### Run Task on Custom Cron Schedule Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Use this method to define a custom cron schedule for task execution. Requires a valid cron string. ```php $schedule->cron('* * * * *') ``` -------------------------------- ### Run Task on Weekdays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run Monday through Friday. Accepts an optional time string. ```php $schedule->weekdays('1:23pm') ``` -------------------------------- ### Restrict Task to Specific Environments Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Limits the task to run only in the specified environments (e.g., 'local', 'prod'). ```php $schedule->environments('local', 'prod') ``` -------------------------------- ### Run Task Hourly Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run at the top of every hour. Optionally specify a minute for execution (e.g., 15 for 12:15 am). ```php $schedule->hourly() ``` ```php $schedule->hourly(15) ``` -------------------------------- ### Run Task on Fridays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Friday. Accepts an optional time string. ```php $schedule->fridays('3:15am') ``` -------------------------------- ### Run Task on Thursdays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Thursday. Accepts an optional time string. ```php $schedule->thursdays('3:15am') ``` -------------------------------- ### Schedule an Event Task Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Schedule a task to trigger a pre-defined framework event. This allows for more dynamic actions. ```php $schedule->event('reminders')->weekdays()->at('9:00 am'); ``` -------------------------------- ### Run Task on Weekends Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run on Saturdays and Sundays. Accepts an optional time string. ```php $schedule->weekends('2:34am') ``` -------------------------------- ### Schedule a Shell Command Task Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Schedule a task to execute a shell command directly on the system. Use with caution and ensure proper sanitization. ```php $schedule->shell('cp foo bar')->daily()->at('11:00 pm'); ``` -------------------------------- ### Run Task on Specific Days of the Week Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only on the specified days of the week, where 0 represents Sunday and 6 represents Saturday. ```php $schedule->days([0,3]) ``` -------------------------------- ### Run Task on Sundays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Sunday. Accepts an optional time string. ```php $schedule->sundays('3:15am') ``` -------------------------------- ### Schedule a Queue Job with Single Instance Lock Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Prevent multiple instances of a queue job from running simultaneously by using `singleInstance()`. The lock is applied when the job is queued. ```php $schedule->queue('queue-name', 'jobName', ['data' => 'array'])->hourly()->singleInstance(); ``` -------------------------------- ### Run Task on Saturdays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Saturday. Accepts an optional time string. ```php $schedule->saturdays('3:15am') ``` -------------------------------- ### Require Specific Version via Composer Source: https://github.com/codeigniter4/tasks/blob/develop/docs/installation.md Alternatively, specify an explicit version constraint, such as the 'dev-develop' branch, to resolve minimum-stability issues. ```bash composer require codeigniter4/tasks:dev-develop ``` -------------------------------- ### Schedule a CLI Command Task Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Schedule a task to run a defined CLI command. This is the most common type of task. ```php $schedule->command('foo:bar')->nightly(); ``` -------------------------------- ### Run Task at Specific Hours Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only at the specified hours of the day. ```php $schedule->hours([0,10,16]) ``` -------------------------------- ### Define Tasks in CodeIgniter Tasks Config Source: https://github.com/codeigniter4/tasks/blob/develop/README.md Register your tasks within the `init()` method of your `app/Config/Tasks.php` file. This method accepts a Scheduler instance to define commands and their schedules. ```php // app/Config/Tasks.php command('demo:refresh --all')->mondays('11:00 pm'); } } ``` -------------------------------- ### Set Task Lock Duration Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Specify a maximum lock duration in seconds for a task using `singleInstance()`. This prevents indefinitely stuck locks if a task crashes. ```php // Lock for a maximum of 30 minutes (1800 seconds) $schedule->command('demo:heavy-task') ->everyFifteenMinutes() ->singleInstance(30 * MINUTE); ``` -------------------------------- ### Run Task on Wednesdays Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run every Wednesday. Accepts an optional time string. ```php $schedule->wednesdays('3:15am') ``` -------------------------------- ### Schedule a Custom CLI Command Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Use the `command()` method to schedule your custom CodeIgniter CLI commands. Pass the command string with any options or arguments. ```php $schedule->command('demo:refresh --all'); ``` -------------------------------- ### Run Task Between Specific Minutes Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only within a specified range of minutes within an hour (inclusive). ```php $schedule->betweenMinutes(0,30) ``` -------------------------------- ### Run Task at Specific Months Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only in the specified months of the year. ```php $schedule->months([1,7]) ``` -------------------------------- ### Schedule a Closure Task Source: https://github.com/codeigniter4/tasks/blob/develop/docs/vision.md Schedule a task to execute an anonymous function (closure). This is useful for simple, self-contained tasks. ```php $schedule->call(function() { // do something.... })->mondays(); ``` -------------------------------- ### Run Task on Specific Days of the Month Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only on the specified days of the month. ```php $schedule->daysOfMonth([1,15]) ``` -------------------------------- ### Schedule an Event Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Trigger a CodeIgniter event using the `event()` method. Provide the name of the event to be triggered. ```php $schedule->event('Foo')->hourly(); ``` -------------------------------- ### Enable Task Runner Source: https://github.com/codeigniter4/tasks/blob/develop/docs/cli-commands.md Re-enables the task runner if it was previously disabled, allowing all scheduled tasks to resume their execution. ```console php spark tasks:enable ``` -------------------------------- ### Run Task Between Specific Months Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only within a specified range of months (inclusive). ```php $schedule->betweenMonths(4,7) ``` -------------------------------- ### Run Task Between Specific Hours Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Schedules a task to run only within a specified range of hours (inclusive). ```php $schedule->betweenHours(6,12) ``` -------------------------------- ### Prevent Concurrent Task Executions Source: https://github.com/codeigniter4/tasks/blob/develop/docs/basic-usage.md Ensures that only one instance of a task runs at a time. Optionally specify a duration like HOUR. ```php $schedule->singleInstance() ``` ```php $schedule->singleInstance(HOUR) ``` -------------------------------- ### Disable Task Runner Source: https://github.com/codeigniter4/tasks/blob/develop/docs/cli-commands.md Manually disables the task runner. This setting is stored in the database using the Settings library and prevents tasks from running until re-enabled. ```console php spark tasks:disable ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.