简体   繁体   English

从数据库脚本触发重复的 Hangfire 作业

[英]Trigger recurring Hangfire job from database script

I have a pretty complicated sql script which cleans up my database and will be run manually from time to time.我有一个非常复杂的 sql 脚本,它可以清理我的数据库,并且会不时手动运行。 Immediatelly after the script has run I have to start a recurring hangfire job which is usually executed only once per day.脚本运行后,我必须立即启动一个经常性的 hangfire 作业,该作业通常每天只执行一次。

In order not to forget to run the script I would like to trigger the execution directly from the sql script .为了不忘记运行脚本,我想直接从 sql 脚本触发执行 Is there a simple way to modify one of the hangfire tables to achieve this task?有没有一种简单的方法来修改其中一个 hangfire 表来完成这个任务?

Hangfire core version is 1.7.5 Hangfire核心版本为1.7.5

UPDATE: Unfortunately I have not found any hangfire table containing the recurring jobs.更新:不幸的是,我没有找到任何包含重复作业的 hangfire 表。 Therefore I guess they are not persisted at all.因此我猜他们根本没有坚持。 Would it be possible to run a job by just inserting a new line in the HangFire.Job table?是否可以通过在 HangFire.Job 表中插入一个新行来运行作业? Or is this a bad idea?或者这是个坏主意?

Sorry for not following up this question here on stackoverflow.很抱歉没有在 stackoverflow 上跟进这个问题。 Due to the lack of a pure hangfire solution I have finally implemented some custom logic with the help of a separate "DatabaseState" table .由于缺乏纯粹的hangfire解决方案,我终于在单独的“DatabaseState”表的帮助下实现了一些自定义逻辑。

My DatabaseState table has the following fields: DateOfDbUpdate(datetime) and HangfireExecuted(bool).我的 DatabaseState 表具有以下字段:DateOfDbUpdate(datetime) 和 HangfireExecuted(bool)。 Whenever I run my complicated SQL-script I just insert a new entry in the table with the current time and HangfireExecuted = false.每当我运行复杂的 SQL 脚本时,我只是在表中插入一个包含当前时间和 HangfireExecuted = false 的新条目。

In the code I have created a recurring hangfire job which checks every few seconds if there is a new entry in the DatabaseState table with HangfireExecuted == false.在代码中,我创建了一个循环的 hangfire 作业,它每隔几秒检查一次 DatabaseState 表中是否有 HangfireExecuted == false 的新条目。 If it finds such an entry it will start the cleanup job.如果找到这样的条目,它将开始清理工作。

Unfortunately this is not a very clean and direct solution.不幸的是,这不是一个非常干净和直接的解决方案。 I would be happy if someone else comes up with a real hangfire solution.如果有人提出真正的 hangfire 解决方案,我会很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM