forked from m-barthelemy/vapor-queues-fluent-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fully overhaul package for modern Swift/Vapor/Fluent (#1)
Pretty much what it says. Changes in public API: - `JobMetadataMigration` is no longer configurable - `QueuesFluentDbType` has been removed Current plan is for these changes to be tagged as 3.0.0-beta.2
- Loading branch information
Showing
22 changed files
with
703 additions
and
495 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
* @gwynne |
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 |
---|---|---|
@@ -1,26 +1,13 @@ | ||
name: test | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
pull_request: { types: [opened, reopened, synchronize, ready_for_review] } | ||
push: { branches: [ main ] } | ||
|
||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
container: swift:5.2-bionic | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
- name: Run tests with Thread Sanitizer | ||
run: swift test --enable-test-discovery --sanitize=thread | ||
macOS: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Select latest available Xcode | ||
uses: maxim-lobanov/[email protected] | ||
with: | ||
xcode-version: latest | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
- name: Run tests with Thread Sanitizer | ||
run: swift test --enable-test-discovery --sanitize=thread | ||
unit-tests: | ||
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main | ||
secrets: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
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 |
---|---|---|
@@ -1,38 +1,51 @@ | ||
// swift-tools-version:5.4 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
// swift-tools-version:5.8 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "QueuesFluentDriver", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
.macOS(.v10_15), | ||
], | ||
products: [ | ||
.library( | ||
name: "QueuesFluentDriver", | ||
targets: ["QueuesFluentDriver"]), | ||
.library(name: "QueuesFluentDriver", targets: ["QueuesFluentDriver"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), | ||
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"), | ||
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.6.0"), | ||
.package(url: "https://github.com/vapor/queues.git", from: "1.11.1"), | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.92.1"), | ||
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"), | ||
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.45.1"), | ||
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.2"), | ||
.package(url: "https://github.com/vapor/queues.git", from: "1.13.0"), | ||
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "QueuesFluentDriver", | ||
dependencies: [ | ||
.product(name: "Vapor", package: "vapor"), | ||
.product(name: "Fluent", package: "fluent"), | ||
.product(name: "FluentKit", package: "fluent-kit"), | ||
.product(name: "FluentSQL", package: "fluent-kit"), | ||
.product(name: "SQLKit", package: "sql-kit"), | ||
.product(name: "Queues", package: "queues") | ||
], | ||
path: "Sources" | ||
swiftSettings: swiftSettings | ||
), | ||
.testTarget( | ||
name: "QueuesFluentDriverTests", | ||
dependencies: ["QueuesFluentDriver"] | ||
dependencies: [ | ||
.product(name: "XCTVapor", package: "vapor"), | ||
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"), | ||
.target(name: "QueuesFluentDriver"), | ||
], | ||
swiftSettings: swiftSettings | ||
), | ||
] | ||
) | ||
|
||
var swiftSettings: [SwiftSetting] { [ | ||
.enableUpcomingFeature("ForwardTrailingClosures"), | ||
.enableUpcomingFeature("ConciseMagicFile"), | ||
.enableUpcomingFeature("DisableOutwardActorInference"), | ||
.enableUpcomingFeature("StrictConcurrency"), | ||
.enableExperimentalFeature("StrictConcurrency=complete"), | ||
] } |
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,55 @@ | ||
// swift-tools-version:5.9 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "QueuesFluentDriver", | ||
platforms: [ | ||
.macOS(.v10_15), | ||
.iOS(.v13), | ||
.watchOS(.v6), | ||
.tvOS(.v13), | ||
], | ||
products: [ | ||
.library(name: "QueuesFluentDriver", targets: ["QueuesFluentDriver"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "4.92.1"), | ||
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"), | ||
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.45.1"), | ||
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.2"), | ||
.package(url: "https://github.com/vapor/queues.git", from: "1.13.0"), | ||
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "QueuesFluentDriver", | ||
dependencies: [ | ||
.product(name: "Vapor", package: "vapor"), | ||
.product(name: "Fluent", package: "fluent"), | ||
.product(name: "FluentKit", package: "fluent-kit"), | ||
.product(name: "FluentSQL", package: "fluent-kit"), | ||
.product(name: "SQLKit", package: "sql-kit"), | ||
.product(name: "Queues", package: "queues") | ||
], | ||
swiftSettings: swiftSettings | ||
), | ||
.testTarget( | ||
name: "QueuesFluentDriverTests", | ||
dependencies: [ | ||
.product(name: "XCTVapor", package: "vapor"), | ||
.product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"), | ||
.target(name: "QueuesFluentDriver"), | ||
], | ||
swiftSettings: swiftSettings | ||
), | ||
] | ||
) | ||
|
||
var swiftSettings: [SwiftSetting] { [ | ||
.enableUpcomingFeature("ForwardTrailingClosures"), | ||
.enableUpcomingFeature("ExistentialAny"), | ||
.enableUpcomingFeature("ConciseMagicFile"), | ||
.enableUpcomingFeature("DisableOutwardActorInference"), | ||
.enableUpcomingFeature("StrictConcurrency"), | ||
.enableExperimentalFeature("StrictConcurrency=complete"), | ||
] } |
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
71 changes: 71 additions & 0 deletions
71
Sources/QueuesFluentDriver/Documentation.docc/Documentation.md
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,71 @@ | ||
# ``QueuesFluentDriver`` | ||
|
||
@Metadata { | ||
@TitleHeading("Package") | ||
} | ||
|
||
A driver for [Queues]. Uses [Fluent] to store job metadata in an SQL database. | ||
|
||
[Queues]: https://github.com/vapor/queues | ||
[Fluent]: https://github.com/vapor/fluent | ||
|
||
## Overview | ||
|
||
## Getting started | ||
|
||
#### Adding the dependency | ||
|
||
Add `QueuesFluentDriver` as dependency to your `Package.swift`: | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor-community/vapor-queues-fluent-driver.git", from: "3.0.0-beta.2"), | ||
... | ||
] | ||
``` | ||
|
||
Add `QueuesFluentDriver` to the target you want to use it in: | ||
```swift | ||
targets: [ | ||
.target( | ||
name: "MyFancyTarget", | ||
dependencies: [ | ||
.product(name: "QueuesFluentDriver", package: "vapor-queues-fluent-driver"), | ||
... | ||
] | ||
), | ||
] | ||
``` | ||
|
||
#### Configuration | ||
|
||
This package includes a migration to create the database table which holds job metadata; add it to your Fluent configuration as you would any other migration: | ||
|
||
```swift | ||
app.migrations.add(JobModelMigration()) | ||
``` | ||
|
||
Finally, load the `QueuesFluentDriver` driver: | ||
```swift | ||
app.queues.use(.fluent()) | ||
``` | ||
|
||
> Warning: Always call `app.databases.use(...)` **before** calling `app.queues.use(.fluent())`! | ||
## Caveats | ||
|
||
### Polling interval and number of workers | ||
|
||
By default, the Vapor Queues system starts 2 workers per available CPU core, with each worker would polling the database once per second. On a 4-core system, this would results in 8 workers querying the database every second. Most configurations do not need this many workers. | ||
|
||
The polling interval can be changed using the `refreshInterval` configuration setting: | ||
|
||
```swift | ||
app.queues.configuration.refreshInterval = .seconds(5) | ||
``` | ||
|
||
Likewise, the number of workers to start can be changed via the `workerCount` setting: | ||
|
||
```swift | ||
app.queues.configuration.workerCount = 1 | ||
``` |
Oops, something went wrong.