Skip to content

Commit 0eff3c1

Browse files
authored
Add MkDocs-Material (#142)
* add mkdocs * add docs workflow * add publish command * cs fix * remove toc for installation
1 parent 0f4f78c commit 0eff3c1

13 files changed

Lines changed: 547 additions & 172 deletions

File tree

.github/workflows/docs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- 'docs/*'
9+
- 'mkdocs.yml'
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.x
22+
- run: pip install mkdocs-material
23+
- run: mkdocs gh-deploy --force

docs/assets/css/codeigniter.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[data-md-color-scheme="codeigniter"] {
2+
--md-primary-fg-color: #dd4814;
3+
--md-primary-fg-color--light: #ECB7B7;
4+
--md-primary-fg-color--dark: #90030C;
5+
6+
--md-default-bg-color: #fcfcfc;
7+
8+
--md-typeset-a-color: #e74c3c;
9+
--md-accent-fg-color: #97310e;
10+
11+
--md-accent-fg-color--transparent: #ECB7B7;
12+
13+
--md-code-bg-color: #ffffff;
14+
15+
.md-typeset code {
16+
border: 1px solid #e1e4e5;
17+
}
18+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[data-md-color-scheme="slate"] {
2+
--md-primary-fg-color: #b13a10;
3+
--md-primary-fg-color--light: #8d7474;
4+
--md-primary-fg-color--dark: #6d554d;
5+
6+
--md-default-bg-color: #1e2129;
7+
8+
--md-typeset-a-color: #ed6436;
9+
--md-accent-fg-color: #f18a67;
10+
11+
--md-accent-fg-color--transparent: #625151;
12+
13+
--md-code-bg-color: #282b2d;
14+
15+
.hljs-title,
16+
.hljs-title.class_,
17+
.hljs-title.class_.inherited__,
18+
.hljs-title.function_ {
19+
color: #c9a69b;
20+
}
21+
22+
.hljs-meta .hljs-string,
23+
.hljs-regexp,
24+
.hljs-string {
25+
color: #a3b4c7;
26+
}
27+
28+
.hljs-attr,
29+
.hljs-attribute,
30+
.hljs-literal,
31+
.hljs-meta,
32+
.hljs-number,
33+
.hljs-operator,
34+
.hljs-selector-attr,
35+
.hljs-selector-class,
36+
.hljs-selector-id,
37+
.hljs-variable {
38+
color: #c1b79f;
39+
}
40+
41+
.hljs-doctag,
42+
.hljs-keyword,
43+
.hljs-meta .hljs-keyword,
44+
.hljs-template-tag,
45+
.hljs-template-variable,
46+
.hljs-type,
47+
.hljs-variable.language_ {
48+
color: #c97100;
49+
}
50+
51+
.hljs-subst {
52+
color: #ddba52
53+
}
54+
55+
.md-typeset code {
56+
border: 1px solid #3f4547;
57+
}
58+
59+
.md-typeset .admonition.note,
60+
.md-typeset details.note {
61+
border-color: #2c5293;
62+
}
63+
64+
.md-typeset .note > .admonition-title:before,
65+
.md-typeset .note > summary:before {
66+
background-color: #2c5293;
67+
-webkit-mask-image: var(--md-admonition-icon--note);
68+
mask-image: var(--md-admonition-icon--note);
69+
}
70+
71+
}

docs/assets/favicon.ico

4.97 KB
Binary file not shown.

docs/assets/flame.svg

Lines changed: 11 additions & 0 deletions
Loading

docs/assets/js/hljs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
document.addEventListener('DOMContentLoaded', (event) => {
2+
hljs.highlightAll();
3+
});

docs/basic-usage.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Basic Usage
2+
3+
Tasks are configured with the `app/Config/Tasks.php` config file, inside the `init()` method.
4+
Let's start with a simple example:
5+
6+
```php
7+
<?php
8+
9+
namespace Config;
10+
11+
use CodeIgniter\Tasks\Config\Tasks as BaseTasks;
12+
use CodeIgniter\Tasks\Scheduler;
13+
14+
class Tasks extends BaseTasks
15+
{
16+
/**
17+
* Register any tasks within this method for the application.
18+
*
19+
* @param Scheduler $schedule
20+
*/
21+
public function init(Scheduler $schedule)
22+
{
23+
$schedule->call(function() {
24+
DemoContent::refresh();
25+
})->mondays();
26+
}
27+
}
28+
```
29+
30+
In this example, we use a closure to refresh demo content at 12:00 am every Monday morning. Closures are
31+
a simple way to handle quick functions like this. You can also execute server commands, execute custom
32+
CLI commands you have written, call a URL, or even fire off an Event of your choosing. Details are covered
33+
below.
34+
35+
## Scheduling
36+
37+
This is how we can schedule our tasks. We have many options.
38+
39+
### Scheduling CLI Commands
40+
41+
If you have written your own [CLI Commands](https://codeigniter.com/user_guide/cli/cli_commands.html), you
42+
can schedule them to run using the `command()` method.
43+
44+
```php
45+
$schedule->command('demo:refresh --all');
46+
```
47+
48+
The only argument is a string that calls the command, complete with an options or arguments.
49+
50+
### Scheduling Shell Commands
51+
52+
You can call out to the server and execute a command using the `shell()` method.
53+
54+
```php
55+
$schedule->shell('cp foo bar')->daily()->at('11:00 pm');
56+
```
57+
58+
Simply provide the command to call and any arguments, and it will be executed using PHP's `exec()` method.
59+
60+
!!! note
61+
62+
Many shared servers turn off exec access for security reasons. If you will be running
63+
on a shared server, double-check you can use the `exec` command before using this feature.
64+
65+
### Scheduling Events
66+
67+
If you want to trigger an [Event](https://codeigniter.com/user_guide/extending/events.html) you can
68+
use the `event()` method to do that for you, passing in the name of the event to trigger.
69+
70+
```php
71+
$schedule->event('Foo')->hourly();
72+
```
73+
74+
### Scheduling URL Calls
75+
76+
If you need to ping a URL on a regular basis, you can use the `url()` method to perform a simple
77+
GET request using cURL to the URL you pass in. If you need more dynamism than can be provided in
78+
a simple URL string, you can use a closure or command instead.
79+
80+
```php
81+
$schedule->url('https://my-status-cloud.com?site=foo.com')->everyFiveMinutes();
82+
```
83+
84+
## Frequency Options
85+
86+
There are a number of ways available to specify how often the task is called.
87+
88+
89+
| Method | Description |
90+
|:----------------------------------|:----------------------------------------------------------------------|
91+
| `->cron('* * * * *')` | Run on a custom cron schedule. |
92+
| `->daily('4:00 am')` | Runs daily at 12:00am, unless a time string is passed in. |
93+
| `->hourly() / ->hourly(15)` | Runs at the top of every hour or at specified minute. |
94+
| `->everyHour(3, 15)` | Runs every 3 hours at XX:15. |
95+
| `->betweenHours(6,12)` | Runs between hours 6 and 12. |
96+
| `->hours([0,10,16])` | Runs at hours 0, 10 and 16. |
97+
| `->everyMinute(20)` | Runs every 20 minutes. |
98+
| `->betweenMinutes(0,30)` | Runs between minutes 0 and 30. |
99+
| `->minutes([0,20,40])` | Runs at specific minutes 0,20 and 40. |
100+
| `->everyFiveMinutes()` | Runs every 5 minutes (12:00, 12:05, 12:10, etc) |
101+
| `->everyFifteenMinutes()` | Runs every 15 minutes (12:00, 12:15, etc) |
102+
| `->everyThirtyMinutes()` | Runs every 30 minutes (12:00, 12:30, etc) |
103+
| `->days([0,3])` | Runs only on Sunday and Wednesday ( 0 is Sunday , 6 is Saturday ) |
104+
| `->sundays('3:15am')` | Runs every Sunday at midnight, unless time passed in. |
105+
| `->mondays('3:15am')` | Runs every Monday at midnight, unless time passed in. |
106+
| `->tuesdays('3:15am')` | Runs every Tuesday at midnight, unless time passed in. |
107+
| `->wednesdays('3:15am')` | Runs every Wednesday at midnight, unless time passed in. |
108+
| `->thursdays('3:15am')` | Runs every Thursday at midnight, unless time passed in. |
109+
| `->fridays('3:15am')` | Runs every Friday at midnight, unless time passed in. |
110+
| `->saturdays('3:15am')` | Runs every Saturday at midnight, unless time passed in. |
111+
| `->monthly('12:21pm')` | Runs the first day of every month at 12:00am unless time passed in. |
112+
| `->daysOfMonth([1,15])` | Runs only on days 1 and 15. |
113+
| `->months([1,7])` | Runs only on January and July. |
114+
| `->quarterly('5:00am')` | Runs the first day of each quarter (Jan 1, Apr 1, July 1, Oct 1) |
115+
| `->yearly('12:34am')` | Runs the first day of the year. |
116+
| `->weekdays('1:23pm')` | Runs M-F at 12:00 am unless time passed in. |
117+
| `->weekends('2:34am')` | Runs Saturday and Sunday at 12:00 am unless time passed in. |
118+
| `->environments('local', 'prod')` | Restricts the task to run only in the specified environments |
119+
120+
121+
These methods can be combined to create even more nuanced timings:
122+
123+
```php
124+
$schedule->command('foo')
125+
->weekdays()
126+
->hourly()
127+
->environments('development');
128+
```
129+
130+
This would run the task at the top of every hour, Monday - Friday, but only in development environments.
131+
132+
## Naming Tasks
133+
134+
You can name tasks so they can be easily referenced later, such as through the CLI with the `named()` method:
135+
136+
```php
137+
$schedule->command('foo')->nightly()->named('foo-task');
138+
```
Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,72 @@
11
# CLI Commands
22

33
Included in the package are several commands that can be run from that CLI that provide that bit of emergency
4-
help you might need when something is going wrong with a cron job at 1am on a Saturday.
4+
help you might need when something is going wrong with a cron job at 1am on a Saturday.
55

6-
All commands are run through CodeIgniter's `spark` cli tool:
6+
## Available Commands
77

8-
> php spark tasks:list
9-
> php spark tasks:run
8+
All commands are run through CodeIgniter's `spark` cli tool.
109

11-
## Available Commands
10+
- [tasks:list](#taskslist)
11+
- [tasks:disable](#tasksdisable)
12+
- [tasks:enable](#tasksenable)
13+
- [tasks:run](#tasksrun)
14+
- [tasks:publish](#taskspublish)
1215

13-
**tasks:list**
16+
### tasks:list
1417

15-
> php spark tasks:list
18+
```console
19+
php spark tasks:list
20+
```
1621

1722
This will list all available tasks that have been defined in the project, along with their type and
1823
the next time they are scheduled to run.
1924

2025
+---------------+--------------+-------------+----------+---------------------+-------------+
2126
| Name | Type | Schedule | Last Run | Next Run | Runs |
2227
+---------------+--------------+-------------+----------+---------------------+-------------+
23-
| emails | command | 0 0 * * * | -- | 2020-03-21-18:30:00 | in 1 hour |
28+
| emails | command | 0 0 * * * | -- | 2023-03-21-18:30:00 | in 1 hour |
2429
+---------------+--------------+-------------+----------+---------------------+-------------+
2530

26-
**tasks:disable**
31+
### tasks:disable
2732

28-
> php spark tasks:disable
33+
```console
34+
php spark tasks:disable
35+
```
2936

3037
Will disable the task runner manually until you enable it again. Stores the setting in the default
3138
database through the [Settings](https://github.com/codeigniter4/settings) library.
3239

33-
**tasks:enable**
40+
### tasks:enable
41+
42+
```console
43+
php spark tasks:enable
44+
```
3445

35-
> php spark tasks:enable
46+
Will enable the task runner if it was previously disabled, allowing all tasks to resume running.
3647

37-
Will enable the task runner if it was previously disabled, allowing all tasks to resume running.
48+
### tasks:run
3849

39-
**tasks:run**
50+
```console
51+
php spark tasks:run
52+
```
4053

41-
> php spark tasks:run
42-
4354
This is the primary entry point to the Tasks system. It should be called by a cron task on the server
4455
every minute in order to be able to effectively run all the scheduled tasks. You typically will not
4556
run this manually.
4657

4758
You can run the command and pass the `--task` option to immediately run a single task. This requires
48-
the name of the task. You can either name a task using the `->named('foo')` method when defining the
59+
the name of the task. You can either name a task using the `->named('foo')` method when defining the
4960
schedule, or one will be automatically generated. The name can be found using `tasks:list`.
5061

51-
> php spark tasks:run --task emails
62+
```console
63+
php spark tasks:run --task emails
64+
```
65+
66+
### tasks:publish
67+
68+
```console
69+
php spark tasks:publish
70+
```
71+
72+
This will publish Tasks config file into the current application.

0 commit comments

Comments
 (0)