Quartz.net keeping a single Scheduler running asp.net - asp.net

Am I understanding this correctly?
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
sched.Start();
Is the StdSchedulerFactory a singleton?
What I want to achieve is in my global,asax on Application_Start to start up the quartz scheduler, and then later on in one of my classes create the job, the trigger, get a handle again to the scheduler, and schedule the job/trigger
But as it turns out, I need to re-start the scheduler, I thought it was already started?
Or is there now more than 1 scheduler running?

The typical scenarios when embedding the scheduler in ASP.Net are to:
Create your scheduler as a singleton and then access it using something like Scheduler.Instance.
If you use DI, have the container give you a reference to the (singleton and already started) scheduler.
Use a global variable and have it reference the started scheduler.

Related

Add job inside another job for APSchedule

I am using APScheduler in a FastAPI application. I have a table, where I stored my async tasks. Then, using APScheduler, I would like to read this table every hour and add new jobs (one per row of the table) to the queue. These jobs are light, so using celery is overkilling I feel. However, I have difficulty in starting a job inside another job for APScheduler.
So, the question is how a job can be added inside another job? Any ideas or help are appreciated.
I've also had a problem with this and a simple solution is to have the scheduler as a global variable available in the job's module. You might also have to use the memory store, as it allows for passing unserializable objects.
You can also pass the scheduler to the job, as long as the job is being run on an executor that doesn't require the arguments to be serialized.
For example, you can have a periodic job running on the asyncio executor that gets the scheduler as an argument, and adds further jobs to it, that are to be run with the ProcessPool executor.
For more info, refer to this discussion in the Gitter channel

How Can You Run CRaSH Commands Or A Script On Node Startup?

I need to initialise my Corda nodes by running a few flows to create certain states.
At the moment I am doing it via the CRaSH shell.
e.g.
flow start IOUFlow iouValue: 50, counterparty: Bank1
Is it possible to have the node run a script or some commands on node startup to do this automatically?
If not, how can I write a bash script to automate these CRaSH commands?
Corda 4.4 introduces a new feature to register actions to be performed on node startup.
You could register an action to be performed on node startup using a CordaService.
appServiceHub.register(
AppServiceHub.SERVICE_PRIORITY_NORMAL,
event -> {
// Your custom code to be run on startup.
}
);
You might want to check on the event type to keep it future proof, but currently the ServiceLifecycleEvent just has a single STATE_MACHINE_STARTED enum.

How to get workflow taskId in Alfresco process service using script task

I wanted to get workflow taskId in a script task variable(Java Script/Groovy) and want's display it on user form.
Please let me know if you have any Idea regarding this.
we are using Alfresco process service 1.9 version
Thanks in Advance.
Store the taskId in a process variable using a *ExecutionListener. create a spring bean that implements the activiti Execution Listener, in the overriden method notify(DelegateExecution execution) set your variable like:
execution.setVariable("your_var", your_var_value);
In the Script Task you can access process variables using the Execution. e.g.:
execution.getVariable("your_var");
follow the developer series for more details.

How to add email scheduler in asp.net?

I want to configure e-mail scheduler in an Asp.net web application and I don't know how to achieve this thing. Does anybody have any idea how I can achieve this? I just want to send emails at specific time.
You can use scheduler frameworks such as Quartz.net. You can create Jobs in Quartz.net and creates triggers. Triggers kicks in the job at particular time, day, month, nightly basis etc etc. You will be using Cron scheduler to schedule your jobs (that is triggers).
I think the easiest way would be to write a good old fashioned console program which sends the emails when it runs. Then you simply use a scheduler to run it on the time(s) you want.
I use next solution.
In your Global.asax add this line to Application_Start method:
this.Application["Timer"] = new Timer(new TimerCallback(EMailProcessor.Process), null, 0, 60000);
Your EMailProcessor class may look like:
public class EMailProcessor
{
public static void Process(object state)
{
// Your code here
}
}
Hope this is what you need.
UPD: This works because the asp.net application are 'real' applications and running even there are no requests to the server.

Guidance on how to build a scheduler in ASP.NET MVC 4

I have a simple question to ask.. Does anyone know how to create a repetitive scheduler in ASP.NET MVC 4. What I'm attempting to build is an Irrigation System that I can set the days of the week and times for my system to activate each week. So the user would select the Day of the week along with the time and duration the system should run. How do I keep a running clock that triggers the system to turn on?.. Should I use a drop down list for my properties? Although it would be nice, I'm not asking for you to write an entire application for me.. A simple point in the right direction would help tremendously.. The problem with searching for the answers over the net is I really don't know what to search for.
Thank you in advance..
We are using Quartz.Net exactly for this. It is a port of Quartz for Java.
It is very powerful and it is quite easy to define new jobs (what should be done) and schedules (when to do it).
The new versions support a Cron scheduler which supports linux cron like configuration - so it is quite easy to start a job on every monday, or on every 5th of the month or for every 5 minutes on a given date. I think it's hard for scheduled tasks to beat this flexibility.
We are using the database configuration and a service on the server (this is the "running clock which activates things). Additionally a web services is used to configure the Quartz scheduler and the running service is changed through the database (this is done by Quartz.Net for you). All these things are supported nicely with it.
Some tips to start with cron triggers:
First thing would be the tutorial from http://quartznet.sourceforge.net/tutorial/lesson_1.html .
Lessons 1 - 3 show you the basic building blocks. Lesson 9 shows you the ADO job store (for db persistance).
Working with the cron trigger would work like this
ITrigger trigger = TriggerBuilder.Create().WithIdentity(id).StartNow().WithCronSchedule(cronstring).Build();
scheduler.ScheduleJob(job, trigger);
To give you an idea of the possibilites of the cron trigger this guide comes handy.
Follow this link:
http://scheduler-net.com/docs/simple_.net_application_with_scheduler.html
http://blog.scheduler-net.com/post/2012/10/29/5-Steps-to-a-Simple-Scheduler-in-ASPNET-MVC3MVC4.aspx
Scheduler for Web application ASP.NET MVC
Friend, you can create a scheduler with the help of following code
void Application_Start(object sender, EventArgs e)
{
System.Threading.Timer _timer = new System.Threading.Timer(
new TimerCallback(GetProducts));
_timer.Change(0, 51000); // here you can change the start time interval
}
static void GetProducts(Object state)
{
// do something
}
To make scheduled tasks on an independent date time server, and get detailed reports about all tasks, you can use A Trigger as a scheduling service. abilities such as pause, resume or delete sets of tasks using tags, archiving and storing all call results such as possible errors will really help developers independent of the programming language.
.Net library is also available:
//Create
ATrigger.Client.doCreate(TimeQuantity.Day(), "1", "http://www.example.com/myTask?something", tags);
Disclaimer: I was amoung ATrigger builders. It's an absolutely freeware, not commercial purpose.

Resources