计划任务限制(或如何实现任务持久性)?

时间:2016-07-08 07:09:44

标签: c# hangfire

我开始阅读Hangfire文档,但没有发现任务限制。

如宣布的那样,任务(或工作)存储在某处。

由于他们只是代表,因此据我所知,唯一可以存储的是代表" body" (IL?)。但是可能存在闭包,它为任务提供了一些上下文,例如,一些外部服务,可能需要加载额外的程序集来运行它们的代码等。

Hangfire如何处理此问题?
任务可以包含其正文中的任何说明,还是有任何限制?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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!