hangfireio / hangfire.documentation Goto Github PK
View Code? Open in Web Editor NEWSphinx-based documentation for Hangfire
Home Page: https://docs.hangfire.io
Sphinx-based documentation for Hangfire
Home Page: https://docs.hangfire.io
From my personal experience just recently with getting an ASP.NET Core 3.1 website to always run, I think these docs could be updated. For me, the first step that was needed that's not on the hangfire docs is the same first step seen here where you check for the IIS Server Role called Application Initialization: https://www.taithienbo.com/how-to-auto-start-and-keep-an-asp-net-core-web-application-and-keep-it-running-on-iis/. I also did not need to change the CLR version of the app pool from No Managed Code to v4, which I'm glad since it's not recommended by Microsoft. I also did not need to do the last step where you're editing the web.config used by the site, which I'm also glad because it saved me from having to go through the trouble of setting that url dynamically as part of the automated deployments we do.
I'm wondering if others could give their personal experiences as well because I'm frankly not sure if these steps I didn't need to do are required for older versions of ASP.NET Core, or part of older IIS's, or dependent on the code, or anything crazy like that so I'm hesitant to remove them. I'd like to come up with a way to call that out in the docs like 'may not be required' or something like that but not sure how to word it.
Would there be an interest in adding code samples for F#?
I wouldn't mind working on it (as far as I can of course)
Hi, i need to schedule a job to be executed some time in the future. Some times, the same job could be scheduled twice; for recurrent task, there are identifiers that prevent the duplicated job to be configured (as seen here http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html#specifying-identifiers).
Is there a way to achieve the same for scheduled tasks?
thanks
Hi,
Im trying to write some unit test and verify that a hangfire job would of been created.
I've managed to this for Enqueue but can't get it to work for Scheduled.
Here is the actual implementation -
schedule.HangfireId = _jobClient.Schedule<EmailScheduleService>(x => x.SendEmail(schedule.Id, 0, 0), schedule.ScheduleTimeUTC);
And here is the test i have to verify the method -
_mockHangfireWrapper.Verify(x => x.Schedule<EmailScheduleService>(
b => b.SendEmail(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()),
It.IsAny<DateTime>()), Times.Once);
this is the error im getting -
System.NotSupportedException : Invalid verify on an extension method: x => x.Schedule<EmailScheduleService>(b => b.SendEmail(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), (DateTimeOffset)It.IsAny<DateTime>())
at Moq.Mock.ThrowIfVerifyExpressionInvolvesUnsupportedMember(Expression verify, MethodInfo method) in C:\projects\moq4\src\Moq\Mock.cs:line 778
at Moq.Mock.VerifyNonVoid(Mock mock, LambdaExpression expression, Times times, String failMessage) in C:\projects\moq4\src\Moq\Mock.cs:line 293
at Moq.Mock`1.Verify[TResult](Expression`1 expression, Func`1 times) in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 464
at XUnitTest.Services.EmailScheduleServiceTest.ScheduleEmail_SuccessullSchedule() in C:\WS\TS\NotificationAPI\XUnitTest\Services\EmailScheduleServiceTest.cs:line 863
--- End of stack trace from previous location where exception was thrown ---
We have found that the use of cancellation tokens (using Hangfire v.1.6.22+) can generate a lot of database load and can significantly reduce performance of long running tasks if called too frequently. More clarity in the documentation regarding "Using cancellation tokens" that it triggers code blocking database calls should be mentioned to help other Hangfire users improve their task performance when faced with this issue.
I NEED HELP
when i host the service in service log it is thowing an error like
Application: demo.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(System.Data.ProviderBase.DbConnectionPoolIdentity, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SqlCredential, System.Object, System.String, System.Security.SecureString, Boolean, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SessionData, System.Data.ProviderBase.DbConnectionPool, System.String, Boolean, System.Data.SqlClient.SqlAuthenticationProviderManager)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Object, System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Data.Common.DbConnectionOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, UInt32, Boolean, Boolean, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource
1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal, System.Data.ProviderBase.DbConnectionInternal ByRef)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource
1<System.Data.ProviderBase.DbConnectionInternal>, System.Data.Common.DbConnectionOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource1<System.Data.ProviderBase.DbConnectionInternal>) at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource
1<System.Data.ProviderBase.DbConnectionInternal>)
at System.Data.SqlClient.SqlConnection.Open()
at Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection()
at Hangfire.SqlServer.SqlServerStorage.UseConnection[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Data.Common.DbConnection, System.Func2<System.Data.Common.DbConnection,Boolean>) at Hangfire.SqlServer.SqlServerStorage.UseConnection(System.Data.Common.DbConnection, System.Action
1<System.Data.Common.DbConnection>)
at Hangfire.SqlServer.SqlServerStorage.Initialize()
at Hangfire.SqlServer.SqlServerStorage..ctor(System.String, Hangfire.SqlServer.SqlServerStorageOptions)
at Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(Hangfire.IGlobalConfiguration, System.String)
at MyFirstWindowsService.Service1..ctor()
at demo.Program.Main()
and my code is
using Hangfire;
using System.IO;
using System.ServiceProcess;
namespace MyFirstWindowsService
{
public partial class Service1 : ServiceBase
{
private BackgroundJobServer _server;
public Service1()
{
InitializeComponent();
GlobalConfiguration.Configuration.UseSqlServerStorage("connection string");// i have done the connection string
}
protected override void OnStart(string[] args)
{
LogService("Service is Started");
_server = new BackgroundJobServer();
RecurringJob.AddOrUpdate("id", () => LogService("job started"), Cron.Minutely);
}
protected override void OnStop()
{
LogService("Service Stoped");
}
private void LogService(string content)
{
FileStream fs = new FileStream(@"C:\harsha\log.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}
}
}
http://docs.hangfire.io/en/latest/users-guide/background-methods/writing-unit-tests.html
Given the following line-to-test:
client.Enqueue(() => CheckForSpam(comment.Id));
And the call verification (using Moq):
client.Verify(x => x.Create(
It.Is<Job>(job => job.Method.Name == "CheckForSpam" && job.Arguments[0] == comment.Id.ToString()),
It.IsAny<EnqueuedState>());
The transition from the Enqueue
method to the Create
method is not obvious, and there should be a note that Enqueue
, Schedule
and other methods are made as extensions.
There should be documentation showing how to configure hangfire in production for an OWIN server which does not have the HttpApplication class.
The page http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html could have a section for OWIN exclusive config.
On the page https://github.com/HangfireIO/Hangfire.Documentation/blob/master/configuration/using-sql-server.rst it references the Install.sql, as well as mentioning in passing which permissions it needs.
Clearly it needs db_reader and db_writer, as well as CREATE/ALTER/DROP Table/Index, but it feels like it would be useful to include the minimum SQL rights that the Hangfire user would need within the documentation.
Classic issue is when using NHibernate is when transaction get's distributed. Since this kind of solution mostly works in a web environment, in a single DB model, re-using NHibernate's ADO-DB connection would save us from distributed transactions (and it's side effects when using then with NHibernate).
This request relates to publishing only: since you want to execute some code then in the end publish a task - and these 2 must be done in a transaction...
The job-servers does not need this feature.
Searching the docs for this shows nothing.
In the manual migration, both of the DefaultInstall.sql and Install.sql links appear to be referencing 1.7 files. Please update these to reference the 1.8 files.
In Hangfire 1.5 the IBackgroundProcess
interface was introduced. We are currently working on a system where we need a process that is running throughout the lifetime of our application (hosted on IIS). The IBackgroundProcess
seems the way to go, but there is nothing documented regarding that subject.
Is this actually a feature or should we stay away from it?
How can we find the state of a background job as it does not have a recurring job ID.
IStorageConnection connection = JobStorage.Current.GetConnection();
var job = connection.GetRecurringJobs().Single(x => x.Job.Method.Name == recurringJobName);
JobData jobData = connection.GetJobData(job.Id);
string stateName = jobData.State;
Can this value be found as this wouldn't be part of the GetRecurringJobs() method?
In index.rst it states that old data is removed automatically:
"Server is also responsible to keep the storage clean and remove old data automatically."
How often and which data is removed? Are there any ways to change configuration of that or do you have to write a cleanup job your self?
E.g. to make sure that database does not fill to much.
In .NET 6, without global.asax, what do we have to do to make Hangfire start right up? And how does the part about making it stop on application end work?
How can I customize the existing dashboard?
I am your fans!But I donot found is there any Chinese Documentation for Hangfire!
So I start to translate. The repository is https://github.com/jonechenug/Hangfire-Chinese-Doc
I am love to share Hangfire and hope more Chinese Developer use Hangfire!
Maybe it is no best translation,but I hope every Chinese Developer can see the Chinese Documentation when they visiting the Hangfire-Documentation website!
May you add Chinese Documentation to the website?
When a batch job completes, how do we programmatically know
In our case if a batch completes and its awaiting job does its cleanup work, we want it to be able to report / alert us of there were issues.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.