Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduled tasks limitations (or how tasks persistence is implemented)?

Tags:

c#

hangfire

I've started to read Hangfire documentation, and found nothing about task limitations.

As declared, tasks (or jobs) are stored somewhere.

Since they are just delegates, the only thing could be stored, as far as I understand, is a delegate "body" (IL?). But there could be closures, that provides some context for the task, e.g., some external services, that can require to load extra assemblies to run their code, etc.

How Hangfire deals with this?
Can task contain any instructions in its body, or there are any limitations?

like image 743
Dennis Avatar asked Jul 08 '16 07:07

Dennis


1 Answers

When you create a job it calls Job.FromExpression, if you pass it anything other than a method call expression it throws an exception. So the only thing you can pass in to BackgroundJob.Enqueue is a single line where that line calls a function.

It then serializes they type of the object and all passed in parameters in to JSON using JobHelper.ToJson. When you pass in a instance of a class the instance is not serialized, only the type is, if the execution crosses process boundaries it will loose internal state.

You may want to read up on the blog article on the old hangfire blog site "Are your methods ready to run in background?"

like image 135
Scott Chamberlain Avatar answered Sep 28 '22 09:09

Scott Chamberlain