Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async support for storage API #401

Open
sergeyzwezdin opened this issue Jul 12, 2015 · 6 comments
Open

Async support for storage API #401

sergeyzwezdin opened this issue Jul 12, 2015 · 6 comments

Comments

@sergeyzwezdin
Copy link
Contributor

Modern data access libraries are migrating to async methods in their API. For example, updated MongoDB driver rewritten with async support.

On the other hand, HangFire have synchronous API for internal objects like IStorageConnection, IFetchedJob, IMonitoringApi, IWriteOnlyTransaction and so on.

It forces to use workarounds like AsyncHelper to build custom storage for HangFire.

So my suggestion is to update API in async way (e.g. return Task<TResult> instead of TResult).

@odinserj
Copy link
Member

I'm suggesting to use async methods too to keep up with the times, but the changes will be introduced in 2.0 version (next year), because of a lot of breaking changes. I'm planning to make background processes async as well (#150) to gain more opportunities from async storage methods.

@sergeyzwezdin
Copy link
Contributor Author

Really cool news. Do you have an idea about dates at next year? I will need to make these changes for mongo as well.

@Gillardo
Copy link

Gillardo commented Dec 9, 2015

Any news on async support yet? Just started using Hangfire, but looks like i may have to stop as it seems it does current support my codebase and i aint updating it all to run using non-await calling just to use hangfire

@IanYates
Copy link

IanYates commented Dec 9, 2015

You can use

var task = Task.Run( async ()=>   {
   var x = bleh;
   await y();
   return z;
});

task.Wait();

It's OK (not perfect) from within Hangfire - there won't be any ugly deadlock. However you will have one of Hangfire's thread's waiting on your separately executing Task to finish. Not the end of the world.

You can also use https://github.com/StephenCleary/AsyncEx/wiki/AsyncContext to do something similar.

Having said that, proper async support in v2.0 next year will be awesome :)

@mlewski
Copy link

mlewski commented May 27, 2016

+1, @odinserj, per comment above, could you add to the 2.0 issue-milestone?

@anasmohad
Copy link

anasmohad commented Mar 17, 2017

Till the Hangfire supports async/await, is it a good idea to encapsulate the call of the jobs creations methods within fire and forget APIs such as HostingEnvironment.QueueBackgroundWorkItem or StephenCleary/AspNetBackgroundTasks ?

examples:

HostingEnvironment.QueueBackgroundWorkItem((cancelationToken) => BackgroundJob.Enqueue(() => SomeClass.DoWork()));

or

BackgroundTaskManager.Run(() =>
{
  BackgroundJob.Enqueue(() => SomeClass.DoWork());
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants