Code Monkey home page Code Monkey logo

Comments (23)

wanglei8888 avatar wanglei8888 commented on June 21, 2024 1

我还发现一个问题、回调函数执行的方法里打印无法生效
image
image
image

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

image

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

请问可以再job.agent里面打印表头这种操作吗?或者带入的参数

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

image
这个里面

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

你是希望拿什么信息呢?
有试过从jobContext里面拿param吗

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

我是希望拿从父接口传入的信息,检测是否传正确得值例如:
Uploading image.png…

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

image

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

jobContext对象里面有个Headers 你试试

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

image
获取没问题了
再冒昧的请教一个问题,我查询数据添加了sqlsugar的过滤器,会为所有表格添加一个过滤条件,但是这个过滤条件是从jwt鉴权的信息里面获取,但是我看job.agent 带上头部也不会获取到鉴权信息,job.agent是不是不是不是通过http方式实现的?事通过什么方式实现的? 请问我这个问题,有方法解决吗?

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

image

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

hangfire是通过http方式请求调度agent的

如果你在agent上加过滤器的话 可能你需要把你的过滤器middlerware的顺序放在hangfireagent的middlerware的前面才会生效把。
https://github.com/yuzd/Hangfire.HttpJob/blob/master/Agent/Hangfire.HttpJob.Agent/JobAgentMiddleware.cs

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

image
你如果有时间的话,https://github.com/wanglei8888/HuanTian 这里有demo(HuanTian.Store项目),里面有我的注册顺序

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

即使放最后注册中间件也无法获取,请问有合适的解决方案推荐吗?

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

建议啦代码调试下
理论上控制middreware的顺序应该是可行的额

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

agent的请求接收是封装在一个middreware的
如果你的filter 能作用在这一层之前拿到请求进行处理 应该是可行的

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

1702014396212
1702014396218
因为有默认的Authorization,替换成其他的就可以了。
1702014398125
1702014396224
明明依赖注入的时候有值,但是进入方法之后,IHttpContextAccessor 值又为null了,不知道为什么

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

原来被替换了

依赖注入没有,感觉像是HttpContextAccessor的使用方式有点问题
你参考下
https://stackoverflow.com/questions/52927463/access-httpcontextaccessor-from-startup-cs-in-net-core-webapi

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

我看了下源码,开了一个线程去执行这个任务,但是依赖注入被替换了. 这应该算是程序BUG把? 你提供的方法,解决不了,因为IHttpContextAccessor 为null,如何调用也是null

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

demo,我发你qq邮箱了

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

好的 我看下

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

agent的job收到了server的调度的时候,会开启一个新的线程去执行,只有这样才能执行长时间运行的任务,是这么设计的
至于为啥IHttpContextAccessor 对象的HttpContext为啥为null
在Construct构造方法的时候你看是有值的。
但是由于是异步执行job的OnStart方法,
执行构造方法的http请求线程已经处理完了,导致HttpContext变成null

不建议在Onstart方法里面去读取IHttpContextAccessor.HttpContext
你需要用到header信息应该直接从JobContext上下文中去拿

from hangfire.httpjob.

wanglei8888 avatar wanglei8888 commented on June 21, 2024

多谢了,作者大大!
我用的sqlSugar租户过滤器,每次查询都需要获取当前登陆用户的租户、 那看来使用httpjob更好一些,能完全契合框架,jobAgent不太适合我这种

from hangfire.httpjob.

yuzd avatar yuzd commented on June 21, 2024

好的

from hangfire.httpjob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.