Method works, but not with hangfire

recurring
Tags: #<Tag:0x00007f49a6db83e0>

#1

Maybe there are some main problem where should I look for such error

Basically when I run this method simple from url, it works fine. As soon asI schedule it I’m gettign this error.


#2

Can you provide a sample of your job enqueuing?

Also It would useful to provide where the exception is happening (It looks like it’s in your controller constructor)

Is the exception occurring at enqueuing time or at execution time?


#3

Method VerifyListAddressBackground is for starting background job.

What foreach list or items ValidateAddress - verify address with some API
And update address in databases
UpdatePropertyAddressValidated
UpdateOwnerAddressValidated

Please ask if any questions. This is already the second method what works fine in a normal way but as soon as I try background it getting error

Thanks


#4

My suggestion is to create a separate “business logic” class that would do the work.

You’re currently enqueuing a job that’s inside of your controller, thus when hangfire tries to create that controller, i’m pretty sure it has a difficult time since it doesn’t have an HttpContext and such.

If you move your work inside a business logic class, there shouldn’t be any problem anymore.

I would also suggest you to look into seperation of concerns, your controller seems to do a lot of job (presentation, business logic and data access)


#5

Yes, there was a problem with accessing HttpContext therefore userId.
Thank You for a suggestion about SoC, looking into that.
Thanks