Skip to content

Commit dfe5558

Browse files
committed
chore: move db creation to schema file
1 parent 8f1a767 commit dfe5558

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

src/Queue/Adapters/Database.php

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public function connect($connection)
5050
*/
5151
public function pushJobToQueue($job)
5252
{
53-
if (!$this->db->tableExists($this->config['table'])) {
54-
$this->setupAdapterStorage();
55-
}
56-
5753
$this->db
5854
->insert($this->config['table'])
5955
->params($job)
@@ -97,10 +93,10 @@ public function setJobStatus($id, $status)
9793
$this->db
9894
->update($this->config['table'])
9995
->params([
100-
"status" => $status,
96+
'status' => $status,
10197
])
10298
->where([
103-
"id" => $id,
99+
'id' => $id,
104100
])
105101
->execute();
106102

@@ -118,50 +114,17 @@ public function setJobStatus($id, $status)
118114
*/
119115
public function markJobAsFailed($id)
120116
{
121-
$this->db
122-
->update($this->config['table'])
123-
->params([
124-
"status" => "failed",
125-
])
126-
->where([
127-
"id" => $id,
128-
])
129-
->execute();
130-
131-
if ($this->db->errors()) {
132-
$this->errors = $this->db->errors();
133-
134-
return false;
135-
}
136-
137-
return true;
138-
}
139-
140-
/**
141-
* Setup storage for the adapter
142-
*/
143-
protected function setupAdapterStorage()
144-
{
145-
$this->db
146-
->createTable($this->config['table'], [
147-
'id' => 'INT NOT NULL AUTO_INCREMENT',
148-
'class' => 'VARCHAR(255)',
149-
'config' => 'TEXT',
150-
'status' => 'VARCHAR(50)',
151-
'retry_count' => 'INT',
152-
'created_at' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
153-
'updated_at' => 'DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
154-
'PRIMARY KEY' => '(ID)',
155-
])
156-
->execute();
117+
return $this->setJobStatus($id, 'failed');
157118
}
158119

159120
/**
160121
* @inheritDoc
161122
*/
162123
public function getJobs()
163124
{
164-
return [];
125+
return $this->db
126+
->select($this->config['table'])
127+
->get();
165128
}
166129

167130
/**

0 commit comments

Comments
 (0)