-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from michalsn/feat/priority
feat: Add priority to the queue
- Loading branch information
Showing
21 changed files
with
500 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Database/Migrations/2023-11-05-064053_AddPriorityField.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Michalsn\CodeIgniterQueue\Database\Migrations; | ||
|
||
use CodeIgniter\Database\BaseConnection; | ||
use CodeIgniter\Database\Migration; | ||
|
||
/** | ||
* @property BaseConnection $db | ||
*/ | ||
class AddPriorityField extends Migration | ||
{ | ||
public function up() | ||
{ | ||
$fields = [ | ||
'priority' => [ | ||
'type' => 'varchar', | ||
'constraint' => 64, | ||
'null' => false, | ||
'default' => 'default', | ||
'after' => 'payload', | ||
], | ||
]; | ||
|
||
$this->forge->addColumn('queue_jobs', $fields); | ||
$this->forge->addColumn('queue_jobs_failed', $fields); | ||
|
||
// Ugly fix for dropping the correct index | ||
// since it had no name given | ||
$keys = $this->db->getIndexData('queue_jobs'); | ||
|
||
foreach ($keys as $key) { | ||
if ($key->fields === ['queue', 'status', 'available_at']) { | ||
$this->forge->dropKey('queue_jobs', $key->name, false); | ||
break; | ||
} | ||
} | ||
|
||
$this->forge->addKey(['queue', 'priority', 'status', 'available_at'], false, false, 'queue_priority_status_available_at'); | ||
$this->forge->processIndexes('queue_jobs'); | ||
} | ||
|
||
public function down() | ||
{ | ||
// Ugly fix for dropping the correct index | ||
$keys = $this->db->getIndexData('queue_jobs'); | ||
|
||
foreach ($keys as $key) { | ||
if ($key->fields === ['queue', 'priority', 'status', 'available_at']) { | ||
$this->forge->dropKey('queue_jobs', $key->name, false); | ||
break; | ||
} | ||
} | ||
|
||
$this->forge->addKey(['queue', 'status', 'available_at']); | ||
$this->forge->processIndexes('queue_jobs'); | ||
|
||
$this->forge->dropColumn('queue_jobs', 'priority'); | ||
$this->forge->dropColumn('queue_jobs_failed', 'priority'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.