vapor/queues

Job not retrying again after an error

quantumass opened this issue · 8 comments

I created a job as defined below it's working fine but once there is an error it doesn't retry again
I added the
context.eventLoop.future(error: Abort(.badRequest, reason: "My error here."))
but the compiler says argument passed to call that takes no arguments

import Foundation
import Jobs
import Vapor

struct SyncCaisseOperationsJob: Job {

    let container: Container

    init(container: Container){
        self.container = container
    }

    func dequeue(_ context: JobContext, _ data: PushCaisseOperationDataJob) -> EventLoopFuture<Void> {

        do {
            let service = try container.make(CaisseServices.self)
            return try service.pushCaisseOperations(
                container,
                caisseId: data.caisse_id,
                cmdClients: data.data,
                urlQuery: data.query
            )
        } catch {
            return Future.map(on: container, { () })
        }
        
    }

}
jdmcd commented

My guess is that it’s not retrying because you’re catching the error and returning success. Try omitting the label on eventLoop.future, I think that might do it.

jdmcd commented

@quantumass Closing this for now, feel free to reopen if you have further questions.

if there is an error during the execution of the job it print an error and delete the record from redis and doesn't retry

import Foundation
import Jobs
import Vapor

struct SyncCaisseOperationsJob: Job {

    let container: Container

    init(container: Container){
        self.container = container
    }

    func dequeue(_ context: JobContext, _ data: PushCaisseOperationDataJob) -> EventLoopFuture<Void> {
        do {
            let service = try container.make(CaisseServices.self)
            return try service.pushCaisseOperations(
                container,
                caisseId: data.caisse_id,
                cmdClients: data.data,
                urlQuery: data.query
            )
        } catch {
            print("ERROR: \(error)")
            return self.error(context, error, data)
            // return Future.map(on: container, { () })
        }
        
    }

}
jdmcd commented

Yes - that's because you're swallowing the error. You need to return that error as a future inside of the catch block if you want it to retry: return context.eventLoop.future(error: error)

@mcdappdev no it doesn't work automaticly it delete the redis row

@mcdappdev sorry, I just figured out that it doesn't print the error inside the catch so it might be a problem with service

@mcdappdev can you help me please
the error doesn't get printed

import Foundation
import Jobs
import Vapor

struct SyncCaisseOperationsJob: Job {

    let container: Container

    init(container: Container){
        self.container = container
    }

    func dequeue(_ context: JobContext, _ data: PushCaisseOperationDataJob) -> EventLoopFuture<Void> {
        do {
            let service = try container.make(CaisseServices.self)
            throw Abort(.badRequest, reason: "error")
            return try service.pushCaisseOperations(
                container,
                caisseId: data.caisse_id,
                cmdClients: data.data,
                urlQuery: data.query
            )
        } catch {
            print("THERE IS")
            print("THERE IS ERROR: \(error)")
            return context.eventLoop.future(error: error)
            // return self.error(context, error, data)
            // return Future.map(on: container, { () })
        }
        
    }

}
jdmcd commented

That should definitely be printing the error. Where are you running this? Mac? Linux?