Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Fluent implementation forhttps://github.com/vapor/queues (Vapor 4)

License

NotificationsYou must be signed in to change notification settings

vapor-community/vapor-queues-fluent-driver

 
 

Repository files navigation

A driver forQueues. UsesFluent to store job metadata in an SQL database.

Compatibility

This package makes use of theSKIP LOCKED feature supported by some of the major database engines (most notablyPostgresSQL andMySQL) when available to make a best-effort guarantee that a task or job won't be picked by multiple workers.

This package should be compatible with any SQL database supported by the various Fluent drivers. It is specifically known to work with:

  • PostgreSQL 11.0+
  • MySQL 5.7+
  • MariaDB 10.5+
  • SQLite

Warning

Although SQLite can be used with this package, SQLite has no support for advanced locking. It is not likely to function correctly with more than one or two queue workers.

Getting started

Adding the dependency

AddQueuesFluentDriver as dependency to yourPackage.swift:

dependencies:[.package(url:"https://github.com/vapor-community/vapor-queues-fluent-driver.git", from:"3.0.0-beta.4"),...]

AddQueuesFluentDriver to the target you want to use it in:

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:

app.migrations.add(JobModelMigration())

Finally, load theQueuesFluentDriver driver:

app.queues.use(.fluent())

Warning

Always callapp.databases.use(...)before callingapp.queues.use(.fluent())!

Options

Using a custom Database

You can optionally create a dedicated non-defaultDatabase with a customDatabaseID for use with your queues, as in the following example:

extensionDatabaseID{staticvarqueues:Self{.init(string:"my_queues_db")}}func configure(_ app:Application)asyncthrows{    app.databases.use(.postgres(configuration:...), as:.queues, isDefault:false)    app.queues.use(.fluent(.queues))}

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. Additionally, when using SQLite as the underlying database it is generally inadvisable to run more than one worker at a time, as SQLite does not have the .

The polling interval can be changed using therefreshInterval configuration setting:

app.queues.configuration.refreshInterval=.seconds(5)

Likewise, the number of workers to start can be changed via theworkerCount setting:

app.queues.configuration.workerCount=1

[8]ページ先頭

©2009-2025 Movatter.jp