Skip to content

Commit

Permalink
Merge pull request #10 from thuotdwz/patch-1
Browse files Browse the repository at this point in the history
Comment out transaction commit in SQLITE pop
  • Loading branch information
m-barthelemy authored May 24, 2020
2 parents 9823601 + 3eb96ea commit 5545f34
Showing 1 changed file with 10 additions and 15 deletions.
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 5545f34

Please sign in to comment.