Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fail a Job #686

Closed
CompassIT-AG opened this issue Aug 18, 2021 · 2 comments
Closed

How to fail a Job #686

CompassIT-AG opened this issue Aug 18, 2021 · 2 comments

Comments

@CompassIT-AG
Copy link

CompassIT-AG commented Aug 18, 2021

Hello,

I just don't understand how you fail a job.
I tried:
job.moveToFailed(`${path} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`, this.scanQueue.token)

But it gives me following error:
Error: Missing lock for job 4. failed at Function.finishedErrors (/Users/admin/repos/ePaadPortal/backend/node_modules/bullmq/src/classes/scripts.ts:248:16) at Job.moveToFailed (/Users/admin/repos/ePaadPortal/backend/node_modules/bullmq/src/classes/job.ts:479:23) at processTicksAndRejections (node:internal/process/task_queues:96:5)

Help would be appreciated. If this is the wrong place to ask this question I am sorry.

Below you find relevant code

public async registerWorkers(): Promise<void>{
        this.scanWorker = new Worker(this.scanQueue.name, async (job:Job) => {
                this.scanInDir(job)
        })
    }
private async scanInDir(job:Job): Promise<void>{
        const directories = readdirSync(this.inDir, { withFileTypes: true})
            .filter(dirent => dirent.isDirectory())
            .map(dirent => dirent.name)
        
        directories.forEach(async (directory) => {
            const _path = path.join(this.inDir, directory)
            try {
                await access(_path, constants.R_OK | constants.W_OK, async (err) => {
                    if(err){
                        Logger.error(`${path} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
                        **HERE I WANT TO FAIL THE JOB**
                    }else{
                        const dirName = `${directory}_${new Date().toISOString().split("T")[0]}`
                        const destination = path.join(this.processDir,`${dirName}`)
                        await move(_path, destination)
                        this.processQueue.add("processDir", {dir: destination})
                    }
                });
              } catch {
                Logger.error(`${path} ist not accessible`);
              }
        })
    }
@manast
Copy link
Contributor

manast commented Aug 19, 2021

Currently you can only fail a job from within the processor function by throwing an exception.

@CompassIT-AG
Copy link
Author

Thank you very much, I will rewrite this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant