Skip to content

Commit 12401b0

Browse files
mychidarkogithub-actions[bot]
authored andcommitted
chore: fix styling
1 parent d29d918 commit 12401b0

File tree

9 files changed

+39
-20
lines changed

9 files changed

+39
-20
lines changed

src/Job.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ public function release($delay = 0)
120120
*/
121121
public static function create(callable $job)
122122
{
123-
//
123+
//
124124
}
125125

126126
public function handle()
127127
{
128-
//
128+
//
129129
}
130130

131131
public static function dispatch($config = [], $queue = 'default')
132132
{
133-
$queue = new Queue;
133+
$queue = new Queue();
134134
$queueConfig = MvcConfig('queue') ?? [];
135135

136136
if (empty($queueConfig)) {

src/Queue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function connect(): Queue
6363

6464
$adapter = ucfirst($config['adapter']);
6565
$adapter = "\\Leaf\\Queue\\Adapters\\$adapter";
66-
66+
6767
$this->adapter = new $adapter($config);
6868
$this->adapter->connect($config['connections'][$config['default'] ?? 'redis']);
6969

@@ -106,7 +106,7 @@ public function pop($id)
106106

107107
/**
108108
* Set job status
109-
*
109+
*
110110
* @param string|int $id The id of the job to set status
111111
* @param string $status The status to set
112112
*/

src/Queue/Adapters/Adapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct($config = []);
1616
* @param array $connection Credentials for the queue storage
1717
*/
1818
public function connect($connection);
19-
19+
2020
/**
2121
* Push job to queue
2222
* @param array $job The job to push to the queue
@@ -31,7 +31,7 @@ public function popJobFromQueue($id);
3131

3232
/**
3333
* Set job status
34-
*
34+
*
3535
* @param string|int $id The id of the job to set status
3636
* @param string $status The status to set
3737
*/

src/Queue/Adapters/Db.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function pushJobToQueue($job)
5555

5656
if ($this->db->errors()) {
5757
$this->errors = $this->db->errors();
58+
5859
return false;
5960
}
6061

@@ -69,12 +70,13 @@ public function popJobFromQueue($id)
6970
$this->db
7071
->delete($this->config['table'])
7172
->where([
72-
"id" => $id
73+
"id" => $id,
7374
])
7475
->execute();
7576

7677
if ($this->db->errors()) {
7778
$this->errors = $this->db->errors();
79+
7880
return false;
7981
}
8082

@@ -89,15 +91,16 @@ public function setJobStatus($id, $status)
8991
$this->db
9092
->update($this->config['table'])
9193
->params([
92-
"status" => $status
94+
"status" => $status,
9395
])
9496
->where([
95-
"id" => $id
97+
"id" => $id,
9698
])
9799
->execute();
98100

99101
if ($this->db->errors()) {
100102
$this->errors = $this->db->errors();
103+
101104
return false;
102105
}
103106

@@ -112,15 +115,16 @@ public function markJobAsFailed($id)
112115
$this->db
113116
->update($this->config['table'])
114117
->params([
115-
"status" => "failed"
118+
"status" => "failed",
116119
])
117120
->where([
118-
"id" => $id
121+
"id" => $id,
119122
])
120123
->execute();
121124

122125
if ($this->db->errors()) {
123126
$this->errors = $this->db->errors();
127+
124128
return false;
125129
}
126130

@@ -141,7 +145,7 @@ protected function setupAdapterStorage()
141145
'retry_count' => 'INT',
142146
'created_at' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
143147
'updated_at' => 'DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
144-
'PRIMARY KEY' => '(ID)'
148+
'PRIMARY KEY' => '(ID)',
145149
])
146150
->execute();
147151
}
@@ -162,7 +166,7 @@ public function getNextJob()
162166
return $this->db
163167
->select($this->config['table'])
164168
->where([
165-
'status' => 'pending'
169+
'status' => 'pending',
166170
])
167171
->orderBy('id', 'asc')
168172
->limit(1)
@@ -178,15 +182,16 @@ public function retryFailedJob($id, $retryCount)
178182
->update($this->config['table'])
179183
->params([
180184
"status" => "pending",
181-
"retry_count" => (int) $retryCount + 1
185+
"retry_count" => (int) $retryCount + 1,
182186
])
183187
->where([
184-
"id" => $id
188+
"id" => $id,
185189
])
186190
->execute();
187191

188192
if ($this->db->errors()) {
189193
$this->errors = $this->db->errors();
194+
190195
return false;
191196
}
192197

src/Queue/Adapters/Redis.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($config = [])
2828
public function connect($connection)
2929
{
3030
$this->redis->init($connection);
31-
31+
3232
if (!$this->redis->get($this->config['table'])) {
3333
$this->redis->set($this->config['table'], json_encode([]));
3434
}
@@ -65,6 +65,7 @@ public function popJobFromQueue($id)
6565
if ($job['id'] === $id) {
6666
unset($jobs[$key]);
6767
$this->redis->set($this->config['table'], json_encode($jobs));
68+
6869
return true;
6970
}
7071
}
@@ -84,6 +85,7 @@ public function setJobStatus($id, $status)
8485
if ($job['id'] === $id) {
8586
$jobs[$key]['status'] = $status;
8687
$this->redis->set($this->config['table'], json_encode($jobs));
88+
8789
return true;
8890
}
8991
}
@@ -105,6 +107,7 @@ public function markJobAsFailed($id)
105107
public function getJobs()
106108
{
107109
$jobs = $this->redis->get($this->config['table']) ?? [];
110+
108111
return json_decode($jobs, true);
109112
}
110113

@@ -136,6 +139,7 @@ public function retryFailedJob($id, $retryCount)
136139
$jobs[$key]['status'] = 'pending';
137140
$jobs[$key]['retry_count'] = (int) $retryCount + 1;
138141
$this->redis->set($this->config['table'], json_encode($jobs));
142+
139143
return true;
140144
}
141145
}

src/Queue/Commands/DeleteJobCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ protected function handle()
2828

2929
if (!file_exists($file)) {
3030
$this->error("$job doesn't exist");
31+
3132
return 1;
3233
}
3334

3435
unlink($file);
3536

3637
$this->comment("$job deleted successfully");
38+
3739
return 0;
3840
}
3941
}

src/Queue/Commands/GenerateJobCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ protected function handle()
2828

2929
if (file_exists($file)) {
3030
$this->error("$job already exists");
31+
3132
return 1;
3233
}
3334

@@ -39,6 +40,7 @@ protected function handle()
3940
file_put_contents($file, $fileContent);
4041

4142
$this->comment("$job generated successfully");
43+
4244
return 0;
4345
}
4446
}

src/Queue/Commands/QueueRunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function handle()
1515
{
1616
$this->writeln('Starting queue worker...');
1717

18-
$queue = new Queue;
18+
$queue = new Queue();
1919
$queueConfigFile = getcwd() . '/config/queue.php';
2020
$queueConfig = [];
2121

src/Worker.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Worker
1313
'timeout' => 60,
1414
'sleep' => 3,
1515
'tries' => 3,
16-
'force' => false
16+
'force' => false,
1717
];
1818

1919
/**
@@ -22,12 +22,14 @@ class Worker
2222
public function config($config)
2323
{
2424
$this->config = array_merge($this->config, $config);
25+
2526
return $this;
2627
}
2728

2829
public function queue($queue)
2930
{
3031
$this->queue = $queue;
32+
3133
return $this;
3234
}
3335

@@ -58,7 +60,7 @@ public function run()
5860
}
5961

6062
$jobConfig = json_decode($jobData['config'] ?? "{}", true);
61-
63+
6264
try {
6365
/** @var \Leaf\Job */
6466
$job = new $jobData['class']($jobData, $jobConfig, $this->queue);
@@ -67,11 +69,13 @@ public function run()
6769

6870
if ($job->hasExpired()) {
6971
$job->handleExpiry();
72+
7073
continue;
7174
}
7275

7376
if ($job->hasReachedRetryLimit()) {
7477
$job->handleRetryLimit();
78+
7579
continue;
7680
}
7781

@@ -84,9 +88,11 @@ public function run()
8488

8589
// at this point, the job has been successfully processed
8690
$job->removeFromQueue();
91+
8792
continue;
8893
} catch (\Throwable $th) {
8994
$job->retry();
95+
9096
continue;
9197
}
9298
}

0 commit comments

Comments
 (0)