- Notifications
You must be signed in to change notification settings - Fork2
A Fluent implementation forhttps://github.com/vapor/queues (Vapor 4)
License
vapor-community/vapor-queues-fluent-driver
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A driver forQueues. UsesFluent to store job metadata in an SQL database.
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.
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"),])]
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())
!
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))}
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
About
A Fluent implementation forhttps://github.com/vapor/queues (Vapor 4)
Resources
License
Stars
Watchers
Forks
Languages
- Swift100.0%