Using HangFire for background job processing without DB storage?
Asked Answered
Z

1

6

I have an ASP.NET 4.6 web API. The app does not have a standalone DB, and it is a micro-service designed for searching files. I want to implement a CRON job in the background and utilize HangFire. The problem is, seems like storage is mandatory, and Memory Storage is not reccomended for production.

What options do I have?

Zoogeography answered 25/6, 2021 at 22:48 Comment(0)
M
2

There isn't any solution to use in production environment but a nuget package exists that help you to use HangFire, it can be useful for testing purpose like check the behavior and use it in a development environment.

  • It should not be used in production (no integrity and no thread safe even if many cases are managed).
  • Data are stored in memory using a dictionary in a static way (See Data created at the storage creation)

Source: Hangfire.MemoryStorage

nuget package : Hangfire.MemoryStorage

GlobalConfiguration.Configuration.UseMemoryStorage();

Above package can't cover in-memory jobs in production environment, but below library provided conditions that can be used in production mode:

Hangfire.InMemory

This is an attempt to create an efficient transactional in-memory storage for Hangfire with data structures close to their optimal representation. The result of this attempt should enable production-ready usage of this storage implementation and handle particular properties of in-memory processing like avoiding OutOfMemoryException at any cost and moderate load on garbage collection. Of course we can't avoid them entirely, but at least can control them somehow.

Miniver answered 25/6, 2021 at 23:1 Comment(2)
What about this library? Seems like it is production ready? github.com/HangfireIO/Hangfire.InMemoryZoogeography
After reviewing the codes of this library, This library has provided conditions that can be used in production environment, it also covers most cases well, but you have to handle memory leak exception by yourself. I add this nuget package with description in this answer to public use.Miniver

© 2022 - 2024 — McMap. All rights reserved.