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

孤街醉人 提交于 2019-12-22 04:18:14

问题


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?


回答1:


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?"




回答2:


It seems the mechanism is based on Expression for scheduling operations and the library is intended for "internal" (in process) execution mainly in ASP.Net websites.

Meaning, all the assemblies needed for execution of a scheduled operation should be already loaded into the web applications memory space, because they were needed to schedule the job (the application wouldn't have compiled if it was missing a Type from an assembly that was not referenced).

Hope it makes things a little bit clearer!



来源:https://stackoverflow.com/questions/38260836/scheduled-tasks-limitations-or-how-tasks-persistence-is-implemented

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!