2

I have an application AngularJS application connected to ASP.NET Web API. I want to generate a new entity and save it to my database every N days(perhaps based off DateTime/Timer). I already have a HTTP method in Web Api to do this. Is there a way for WebAPI to send a message to AngularJS to call that HTTP method, or make WebAPI call itself, or have a completely separate service do this?

I understand that WebAPI should only take requests and not make them, does this mean I should have a separate service of some kind? If not, where does my time calculations take place?

2 Answers 2

1

Is there a way for WebAPI to send a message to AngularJS to call that HTTP method, or make WebAPI call itself, or have a completely separate service do this?

Have a completely separate service to do this. A Windows Service could be a good candidate to perform some recurring background tasks. For example it could call your Web API every N days.

Hosting timers and performing recurring background tasks in ASP.NET could represent some challenges and is not recommended in general.

Sign up to request clarification or add additional context in comments.

1 Comment

Or even a simple exe, with task scheduler can do this.
0

I agree with the previous answer, you would probably be better off using a service to do this logic. If for some reason you needed your JavaScript to do this work, what you could do would be to have the JavaScript/Angular service call on an interval, every 1 minute or 1 hour or whatever makes sense. Then the WebAPI endpoint it called to would determine if it was time to generate the new entity and return true or false. When it returns true, you would then call your existing endpoint that actually creates the entity.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.