Web Application with Background Job That Loops Forever

446 views Asked by At

I am trying to design a new application but am a little stuck on the best way to do it.

What I want to be able to do is have a bot connected to an irc channel which is gathering information from the chat messages and then I want to have an HTTP endpoint where I can get results from the information gathered so far.

I have a bot running that gathers the information I want and I can create endpoints but how do I architecture this into 1 application? Do I have 2 applications? 1 that outputs to a file and the endpoint just reads the file and outputs that? I would prefer it in 1 application but haven't been able to find a solution like this so far.

I am using DotNet core 2.0 currently and deploying to a Raspberry Pi.

1

There are 1 answers

2
Tomasz Żmuda On

It depends of workload. If app gathering information doing it periodically and do nothing rest of the time I would suggest start this as a ASP.NET service:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();
    host.Run();
}

Install all dependencies for you current console app (this will work). To gather data you can use HangFire. It library to run background jobs. To run background job reccurence register job like this:

RecurringJob.AddOrUpdate(
    () => { //Gather data here },
    Cron.Daily);