How to run a web page(aspx) doing a functionality, triggered by windows task scheduler in a new thread? - asp.net

I have a situation in which i am fetching top row from a temporary table and doing a functionality using that details. The temporary table will be updated with the new uploaded file details. I do have an aspx page which does this functionality. The web page is triggered using a task scheduler at some interval of time. My problem is that when the page is triggered
during a schedule if the functionality is not finished before the next trigger the task scheduler gets stuck and won't work unless a new schedule is created.
I have heard that executing the functionality using asp.net threading can solve my problem. Is that possible for my situation? If so any one please help me with code how i can proceed..
Now i just fetch only one top row to do the process. If i can implement this for top few rows (say top 5 rows) then i can increase the speed of my application. Please suggest a solution to implement this as well..

increase the time scheduler time a little bit to it can get completed before another starts.
Improve the update query, so it can save time.
Threading is good idea. But...
Each scheduler should check if the previous one is already running or not, you can put a status of (running/ completed) somewhere in table.
Log scheduler activity (start, end, elapsed time etc), it will help a lot.

Related

Scheduling hangfire jobs in a different project to where they are executed

I have 2 .net core web projects.
One of them is called ScheduledJobs and it uses Hangfire with the dashboard to both schedule and process jobs.
The other is called ClientWebsite and it schedules the jobs only - but I dont want them executing here!
ScheduledJobs works fine, if I schedule anything from there it picks them up and processes them.
But since I need to be able to schedule jobs from clientWebsite too, I have to have the following settings in startup:
services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
services.AddHangfireServer();
If I dont call services.AddHangfireServer it wont even let me schedule them.
But if I add it, then it processes them too which I dont want !
Please help! Thanks
You shouldn't need to register the hangfire service at all in the second project in this way.
If you want to purely queue jobs from it you can use the GlobalConfiguration to set up which database it should point at similar to
GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
Once you have done this you can register a BackgroundJobClient similar to this (this is taken from an autofac example so depending on your DI it wont be exactly the same as the line below)
builder.RegisterType<BackgroundJobClient>().As<IBackgroundJobClient>();
What this then allows you to do is resolve and enqueue jobs using the IBackgroundJobClient in your application without setting up a hangfire server at all.
In your classes where you want to enqueue jobs from you can then simple resolve an instance of IBackgroundJobClient and make use of the Enqueue method such as
_myClient.Enqueue<MyJobClass>(x => x.APublicMethodOnMyJobClass());
Details on the backgroundjobclient can be found here - BackgroundJobClient

alternatives for Implementing a scheduler with resource view in Meteor

We are working a scheduling system for employees we achieved good results using a hacked version of fullcalendar that has a resource view , but we were constrained to put the whole FullCalendar init code in an autoRun block , since there was no working function that allows yuo to refetch resources or just add it programmaticaly , resources could only be added in the init Code , thus we destroy every time the calendar and recreate one on every change rerunning autoRun.
this resulted in bad performing scheduler .
now we are studuying the alternatives to revamp it .
the scheduler should support resource view and also should be used in a 2 weeks view .
what are the solutions available to avoid a from scratsh dev?
Your assumptions are incorrect. You can use FullCalendar to do every thing that you mentioned.
You can see how to re-fetch in the documentations.
Also you can add events programmaticaly with the addResource function - see documentation here.
If you initialize every time of course it will cause bad performing, but you are using it wrong. This whole plugin works with ajax and the performance suppose to be depended only on your server handling.
Last thing, you said "hacked version" of full calendar.
FullCalendar is an open source project, so there is no "hacked", only the latest version... You can download it here.

Quartz.NET: in the Asp.Net Web vs Console Application

I need to run 4 background gobs for cleaning temp files and proccessing some files. I have chosen Quart.net for the job.
I have a Asp.Net website, which accepts uploading files that will be processed by the Quartz Jobs at night.
First i thought about making a console application for the Quartz jobs, keeping the website and the jobs totally decoupled.
But then, i've seen that i will need some config values (connectionstring and paths to files) that are on the asp.net web.config. So a question came to my mind:
Should i run the jobs through the asp.net instance or should i do this on a console application?
Furthermore, i want that when the Quartz jobs start running, the website show a special page (like "We are processing the files...).
What i care the most is the performance, i don't want the website to be affected by the Quartz jobs, neither the jobs' performance affected by the website.
So, what should i do? Have you done something like this and can give me an advice?
Should i run the jobs through the asp.net instance or should i do this on a console application?
If you want to have to manually trigger them each night, sure. But a console application using the host system's task scheduler seems like a more automated solution. A web application is more of a request/response system, it's not really suited for periodic or long-running actions. Scheduling some sort of background operation on the host, such as a scheduled console application or a windows service, would serve that purpose better.
Note that if it truly needs to be unattended and run even when there's nobody logged in to the server console, a windows service may be a more ideal approach than a console application.
i've seen that i will need some config values (connectionstring and paths to files) that are on the asp.net web.config
Console application have App.config files which serve the same purpose. You can use that.
i want that when the Quartz jobs start running, the website show a special page
You definitely want to keep the two de-coupled. But you may be able to accomplish this easily enough. Maybe have some sort of status flag in the database which indicates if any particular record is "currently being processed". The website can simply look for any records with that flag when a page loads and display that message.
There are likely a couple of different ways to synchronize status here, it doesn't really matter what you choose. What does matter is that the systems remain decoupled and that any status which is statically persisted is handled somewhat carefully to avoid an errant process from leaving an incorrect status. (For example, a background task sets a status of "processing" and then fails in some way. The website would forever indicate that it's processing.)

How can I undo the previous step in Windows Workflow Foundation?

I have a project that uses Windows Workflow and I have a database in SQL Server 2008 with Workflow tables.
I want to Edit Record in Project so want to go back to a previous Activity without condition, and update the workflow instance in database.
How can I undo the previous step in Windows Workflow Foundation?
Not really. There is a bit if hack though that might be useful. When you use a workflow instance store and tell the workflow to abandon it's state when an unhandled exception occurs the last saved state in the instance store is unchanged. So you can reload the workflow from that state and continue as if the next activity never executed. The problem is in controlling when the workflow persist. You get to control that for the most part but there are some circumstances where a workflow will always persist.

What would be a good approach to use Thread or Thead Pool in ASP.NET

I am developing a component to create bespoke BulkImport functionality in ASP.NET. Underline this component will be using SqlBulkCopy class. There will be different file formats. The file is imported into a intermidiate table and is then transformed to the required tables. The upload file can be big and might take couple of minutes for processing. I would like to use Thread or Thead Pool to do asynchronous processing. Can you please suggest a good approach to handle this problem.
note: This is an internal application which would be used by max 2-5 person at any given time.
The main problem with firing up additional threads in ASP.NET is that the framework can rip the AppDomain out from under you (for example, if someone edits the web.config or IIS decides to recycle the worker process). If that happens, your worker thread is also terminated and you can't really control it.
If you don't think that'll be a problem, then it doesn't really matter, but I would suggest that a better solution would probably be to fire up the work in a separate process that you can then monitor from your web application.
That way, if someone edits the web config, or IIS recycles the worker process, the import process is running independently and you don't have to worry.
Here is my approach:
Ask the user to paste in the unc path to the file. Save this path into a table in sql.
Write a windows service to check for new entries in the path table. When finding a new entry, start processing the file. Update the tabel periodicly with the progress and check flags (below)
Have an ajax callback in the browser that checks the table for progress, returning as a percentage to the client. Allow the client to stop the process by adding some flags to the table.

Resources