Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barthelemy committed May 31, 2020
2 parents c68a761 + 5545f34 commit c695bbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let package = Package(
...
dependencies: [
...
.package(url: "https://github.com/m-barthelemy/vapor-queues-fluent-driver.git", from: "0.3.6"),
.package(name: "QueuesFluentDriver", url: "https://github.com/m-barthelemy/vapor-queues-fluent-driver.git", from: "0.3.6"),
...
],
targets: [
Expand Down
25 changes: 10 additions & 15 deletions Sources/QueuesFluentDriver/PopQueries/SqlitePopQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@ import Foundation
import SQLKit
import Fluent

// Currently broken
final class SqlitePop : PopQueryProtocol {
func pop(db: Database, select: SQLExpression) -> EventLoopFuture<String?> {
let db = db as! SQLDatabase
//let beginImmediateTrxn = database.raw("BEGIN IMMEDIATE").

//return database.raw(SQLQueryString("BEGIN IMMEDIATE")).run().flatMap { void in
db.transaction { transaction in
let database = transaction as! SQLDatabase
var id: String?
return db.execute(sql: select) { (row) -> Void in

return database.execute(sql: select) { (row) -> Void in
id = try? row.decode(column: "\(FieldKey.jobId)", as: String.self)
}
.flatMap {
guard let id = id else {
return db.eventLoop.makeSucceededFuture(nil)
return database.eventLoop.makeSucceededFuture(nil)
}
let updateQuery = db
let updateQuery = database
.update(JobModel.schema)
.set(SQLColumn("\(FieldKey.state)"), to: SQLBind(QueuesFluentJobState.processing))
.set(SQLColumn("\(FieldKey.updatedAt)"), to: SQLBind(Date()))
.where(SQLColumn("\(FieldKey.jobId)"), .equal, SQLBind(id))
.where(SQLColumn("\(FieldKey.state)"), .equal, SQLBind(QueuesFluentJobState.pending))
.query
return db.execute(sql: updateQuery) { (row) in }
.flatMap {
return db.raw(SQLQueryString("COMMIT")).run().map {
return id
}
}
return database.execute(sql: updateQuery) { (row) in }
.map { id }
}
//}

}
}
}

0 comments on commit c695bbc

Please sign in to comment.