-
-
Notifications
You must be signed in to change notification settings - Fork 1
Adding queue name and change the database schema #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f6e0e3
Conforming to JobQueueDriver
thoven87 a0fe656
Swift format
thoven87 efcac8a
use the queue name from config instead
thoven87 0d11fbe
Removed breaking changes notes from README, keep track of which queue…
thoven87 74e2592
Update Sources/JobsPostgres/PostgresJobsQueue.swift
thoven87 b64d911
make select queue_name implicit and updated the test multiple job que…
thoven87 18ae25e
Deleting unused migrations
thoven87 34a6844
adding migration group
thoven87 74e5989
PR feedback
thoven87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
Sources/JobsPostgres/Migrations/CreateJobQueueMetadata.swift
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
Sources/JobsPostgres/Migrations/CreateSwiftJobsMigrations.swift
This file contains hidden or 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,89 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Logging | ||
import PostgresMigrations | ||
import PostgresNIO | ||
|
||
struct CreateSwiftJobsMigrations: DatabaseMigration { | ||
|
||
func apply(connection: PostgresNIO.PostgresConnection, logger: Logging.Logger) async throws { | ||
|
||
try await connection.query("CREATE SCHEMA IF NOT EXISTS swift_jobs;", logger: logger) | ||
|
||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS swift_jobs.jobs ( | ||
id uuid PRIMARY KEY, | ||
job bytea NOT NULL, | ||
last_modified TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
queue_name TEXT NOT NULL DEFAULT 'default', | ||
status smallint NOT NULL | ||
); | ||
""", | ||
logger: logger | ||
) | ||
|
||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS swift_jobs.queues( | ||
job_id uuid PRIMARY KEY, | ||
created_at TIMESTAMPTZ NOT NULL, | ||
delayed_until TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
queue_name TEXT NOT NULL DEFAULT 'default' | ||
); | ||
""", | ||
logger: logger | ||
) | ||
|
||
try await connection.query( | ||
""" | ||
CREATE INDEX CONCURRENTLY IF NOT EXISTS queues_delayed_until_queue_name_idx | ||
ON swift_jobs.queues(delayed_until, queue_name) | ||
""", | ||
logger: logger | ||
) | ||
|
||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS swift_jobs.queues_metadata( | ||
key text PRIMARY KEY, | ||
value bytea NOT NULL, | ||
queue_name TEXT NOT NULL DEFAULT 'default' | ||
) | ||
""", | ||
logger: logger | ||
) | ||
|
||
try await connection.query( | ||
""" | ||
CREATE INDEX CONCURRENTLY IF NOT EXISTS queues_metadata_key_queue_name_idx | ||
ON swift_jobs.queues_metadata(key, queue_name) | ||
""", | ||
logger: logger | ||
) | ||
} | ||
|
||
func revert(connection: PostgresNIO.PostgresConnection, logger: Logging.Logger) async throws { | ||
try await connection.query( | ||
""" | ||
DROP SCHEMA swift_jobs CASCADE; | ||
""", | ||
logger: logger | ||
) | ||
} | ||
|
||
var description: String { "__CreateSwiftJobsMigrations__" } | ||
var group: DatabaseMigrationGroup { .jobQueue } | ||
} |
This file contains hidden or 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,20 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import PostgresMigrations | ||
|
||
extension DatabaseMigrationGroup { | ||
/// JobQueue migration group | ||
public static var jobQueue: Self { .init("_hb_jobqueue") } | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.