Skip to content

Commit 721a228

Browse files
committed
feat: add config generation command
1 parent 0ea5ec7 commit 721a228

File tree

2 files changed

+275
-0
lines changed

2 files changed

+275
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Leaf\Queue\Commands;
4+
5+
use Aloe\Command;
6+
use Aloe\Core;
7+
8+
class QueueConfigCommand extends Command
9+
{
10+
protected static $defaultName = 'queue:config';
11+
public $description = 'Generate queue config';
12+
public $help = 'Generate queue config';
13+
14+
protected function handle()
15+
{
16+
$this->comment('Generating queue config...');
17+
18+
$appConfigDir = getcwd() . '/config';
19+
$appConfigFile = $appConfigDir . '/queue.php';
20+
21+
if (!Core::isMVCProject()) {
22+
$appConfigDir = getcwd();
23+
$appConfigFile = $appConfigDir . '/queue.config.php';
24+
}
25+
26+
if (file_exists($appConfigFile)) {
27+
$this->error('Queue config already exists');
28+
return 1;
29+
}
30+
31+
if (!copy(__DIR__ . '/stubs/config.stub', $appConfigFile)) {
32+
$this->error('Failed to generate queue config');
33+
return 1;
34+
}
35+
36+
$this->info('Queue config generated successfully');
37+
38+
return 0;
39+
}
40+
}
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Adapter Config
7+
|--------------------------------------------------------------------------
8+
|
9+
| Leaf allows you to use different queue adapters through the same API,
10+
| giving you convenient access to various queue backends using the same
11+
| syntax for each one. Here you may set the default queue adapter.
12+
|
13+
| Supported: "redis", "db". Others will be added in the future.
14+
|
15+
*/
16+
'adapter' => 'redis',
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Default Queue Connection
21+
|--------------------------------------------------------------------------
22+
|
23+
| Here you may specify which of the queue connections below you wish
24+
| to use as your default connection for all queue work.
25+
|
26+
*/
27+
'default' => 'redis',
28+
29+
/*
30+
|--------------------------------------------------------------------------
31+
| Connection Config
32+
|--------------------------------------------------------------------------
33+
|
34+
| This section sets up the connection for your queue. You can set up
35+
| the credentials you need to connect to your queue here. Leaf
36+
| queue supports redis and database connections.
37+
|
38+
| See https://leafphp.dev/modules/queue#connections for more info
39+
|
40+
*/
41+
'connections' => [
42+
'redis' => [
43+
'host' => _env('REDIS_HOST', '127.0.0.1'),
44+
'port' => _env('REDIS_PORT', '6379'),
45+
'password' => _env('REDIS_PASSWORD', ''),
46+
'dbname' => _env('REDIS_DB', 0),
47+
],
48+
49+
'sqlite' => [
50+
'driver' => 'sqlite',
51+
'url' => _env('DATABASE_URL'),
52+
'database' => _env('DB_DATABASE', DatabasePath('database.sqlite')),
53+
'prefix' => '',
54+
'foreign_key_constraints' => _env('DB_FOREIGN_KEYS', true),
55+
],
56+
57+
'mysql' => [
58+
'driver' => 'mysql',
59+
'url' => _env('DATABASE_URL'),
60+
'host' => _env('DB_HOST', '127.0.0.1'),
61+
'port' => _env('DB_PORT', '3306'),
62+
'database' => _env('DB_DATABASE', 'test'),
63+
'username' => _env('DB_USERNAME', 'test'),
64+
'password' => _env('DB_PASSWORD', ''),
65+
'unix_socket' => _env('DB_SOCKET', ''),
66+
'charset' => _env('DB_CHARSET', 'utf8mb4'),
67+
'collation' => _env('DB_COLLATION', 'utf8mb4_unicode_ci'),
68+
'prefix' => '',
69+
'prefix_indexes' => true,
70+
'strict' => true,
71+
'engine' => null,
72+
'options' => extension_loaded('pdo_mysql') ? array_filter([
73+
PDO::MYSQL_ATTR_SSL_CA => _env('MYSQL_ATTR_SSL_CA'),
74+
]) : [],
75+
],
76+
77+
'pgsql' => [
78+
'driver' => 'pgsql',
79+
'url' => _env('DATABASE_URL'),
80+
'host' => _env('DB_HOST', '127.0.0.1'),
81+
'port' => _env('DB_PORT', '5432'),
82+
'database' => _env('DB_DATABASE', 'forge'),
83+
'username' => _env('DB_USERNAME', 'forge'),
84+
'password' => _env('DB_PASSWORD', ''),
85+
'charset' => _env('DB_CHARSET', 'utf8'),
86+
'prefix' => '',
87+
'prefix_indexes' => true,
88+
'schema' => 'public',
89+
'sslmode' => 'prefer',
90+
],
91+
92+
'sqlsrv' => [
93+
'driver' => 'sqlsrv',
94+
'url' => _env('DATABASE_URL'),
95+
'host' => _env('DB_HOST', 'localhost'),
96+
'port' => _env('DB_PORT', '1433'),
97+
'database' => _env('DB_DATABASE', 'forge'),
98+
'username' => _env('DB_USERNAME', 'forge'),
99+
'password' => _env('DB_PASSWORD', ''),
100+
'charset' => _env('DB_CHARSET', 'utf8'),
101+
'prefix' => '',
102+
'prefix_indexes' => true,
103+
],
104+
],
105+
106+
/*
107+
|--------------------------------------------------------------------------
108+
| Default Queue Table
109+
|--------------------------------------------------------------------------
110+
|
111+
| This is the name of the table that will be used to store queue jobs.
112+
| You may change the table name to anything you like. If you change
113+
| the table name, don't forget to change it in the migration file. If you
114+
| use redis, this will be the name of the list that will be used to store
115+
| queue jobs.
116+
|
117+
*/
118+
'table' => 'leafphp_main_jobs',
119+
120+
/*
121+
|--------------------------------------------------------------------------
122+
| Worker config
123+
|--------------------------------------------------------------------------
124+
|
125+
| This section sets up the configuration for your worker. This config
126+
| is used by default when you dispatch a job. You can override this
127+
| config by passing a config array to the dispatch method.
128+
|
129+
*/
130+
'workerConfig' => [
131+
/*
132+
|--------------------------------------------------------------------------
133+
| Job execution delay
134+
|--------------------------------------------------------------------------
135+
|
136+
| This option allows you to set a delay for when a job should be executed.
137+
| This is useful for scheduling jobs to run at a later time.
138+
|
139+
*/
140+
'delay' => 0,
141+
142+
/*
143+
|--------------------------------------------------------------------------
144+
| Delay before retry
145+
|--------------------------------------------------------------------------
146+
|
147+
| This option allows you to set a delay for when a job should be retried.
148+
| This is useful when you need to setup something before retrying a job.
149+
|
150+
*/
151+
'delayBeforeRetry' => 0,
152+
153+
/*
154+
|--------------------------------------------------------------------------
155+
| Expire time
156+
|--------------------------------------------------------------------------
157+
|
158+
| This option allows you to set a time limit for how long a job should
159+
| be kept in the queue. This is useful for archiving old jobs that you
160+
| may need to reference later for data or other purposes.
161+
|
162+
*/
163+
'expire' => 60,
164+
165+
/*
166+
|--------------------------------------------------------------------------
167+
| Force job execution
168+
|--------------------------------------------------------------------------
169+
|
170+
| This option allows you to force a job to run even if it has expired or
171+
| reached its retry limit. This is useful for jobs that you need to run
172+
| at all costs.
173+
|
174+
*/
175+
'force' => false,
176+
177+
/*
178+
|--------------------------------------------------------------------------
179+
| Memory limit
180+
|--------------------------------------------------------------------------
181+
|
182+
| This option allows you to set a memory limit for the worker. This is
183+
| useful for preventing memory leaks and other memory related issues.
184+
|
185+
*/
186+
'memory' => 128,
187+
188+
/*
189+
|--------------------------------------------------------------------------
190+
| Quit when queue is empty
191+
|--------------------------------------------------------------------------
192+
|
193+
| This option allows you to set whether the worker should quit when the
194+
| queue is empty. By default, the worker will keep running even when
195+
| the queue is empty. You can set this to true to make the worker quit
196+
| when the queue is empty.
197+
|
198+
*/
199+
'quitOnEmpty' => false,
200+
201+
/*
202+
|--------------------------------------------------------------------------
203+
| Worker sleep time
204+
|--------------------------------------------------------------------------
205+
|
206+
| This option allows you to set how long the worker should sleep when
207+
| the queue is empty. This is useful for preventing the worker from
208+
| consuming too much CPU when the queue is empty.
209+
|
210+
*/
211+
'sleep' => 3,
212+
213+
/*
214+
|--------------------------------------------------------------------------
215+
| Queue timeout
216+
|--------------------------------------------------------------------------
217+
|
218+
| This option allows you to set a timeout for the queue. This is useful
219+
| for preventing the queue from running for too long.
220+
|
221+
*/
222+
'timeout' => 60,
223+
224+
/*
225+
|--------------------------------------------------------------------------
226+
| Job retry limit
227+
|--------------------------------------------------------------------------
228+
|
229+
| This option allows you to set a retry limit for a job. This is useful
230+
| for preventing a job from running too many times.
231+
|
232+
*/
233+
'tries' => 3,
234+
],
235+
];

0 commit comments

Comments
 (0)