I'm trying to get started with Quartz.Net 2.0. A very simple appearing test application is failing with a SchedulerException
Trigger's related Job's name cannot be null
The code is adapted from the Version 2.0 Migration Guide
ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler classSched = schedFact.GetScheduler();
classSched.Start();
IJobDetail job = JobBuilder.Create<ClassificationJob>()
.WithIdentity("myJob", "My Group")
.WithDescription("My Description")
.Build();
TimeZoneInfo tzUtc = TimeZoneInfo.Utc;
DateTime startTime;
startTime = DateTime.UtcNow;
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "My Group")
.WithDescription("My Description")
.StartAt(startTime)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
.Build();
classSched.ScheduleJob(trigger); // Exception on this line
Why is this failing?
I think there are two issues.
Firstly, (despite the example in the migration guide), I think that you need to say which job the trigger is related to, ie call the .ForJob method , for example
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "My Group")
.WithDescription("My Description")
.StartAt(startTime)
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
.ForJob(job)
.Build();
Secondly, the syntax you are using to schedule the job only works if the job has previously been added (eg if you have previously called classSched.AddJob(job,true); // or classSched.AddJob(job,false);
If that hasn't already been done, then you need to use the syntax
classSched.ScheduleJob(job, trigger);
Related
I have set up the notification for cloud build CI/CD which is pushing notification to a respective slack channel.
After a successful build that image push to kubernetes cluster and rolling update strategy followed by deployment.
So I want to push notification when new pod become ready and old pod terminated so that time gets an idea about new changes applied to deployment.
Note : I am using GKE cluster but not installed Prometheus due to resource limits.
There are multiple ways of doing this, I can think of two ways right now:
Use Prometheus + Alert manager to send you a slack notification when pods became ready.
Use CI/CD pipeline to continuously check for the status of the pods, once they are updated successfully, send a notification.
Hope this answers your question.
EDIT:
If you would like to stick to using stackdriver, then there is a solution for it as well: https://kubernetes.io/docs/tasks/debug-application-cluster/events-stackdriver/
If you cannot afford to Prometheus stack due to resources limitation check kubewatch it has slack support build-in so it should be suitable for your needs.
Using kubernetes api watch can be implemented
https://github.com/kubernetes-client/csharp/tree/master/examples/watch
Basically it will check the not running pod and notify using Microsoft Teams web-hook. It will also notify pod which was initially not running and came back to running status again(recovered pod)
C# code snippet below with Main and Notify function.
You can replace the deployment over pod
static async Task Main(string[] args)
{
// Load from the default kubeconfig on the machine.
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
// Use the config object to create a client.
var client = new Kubernetes(config);
try
{
var podlistResp = await client.ListNamespacedPodWithHttpMessagesAsync(Namespace, watch: true);
using (podlistResp.Watch<V1Pod, V1PodList>(async (type, item) =>
{
Console.WriteLine(type);
Console.WriteLine("==on watch event==");
var message = $"Namespace: {Namespace} Pod: {item.Metadata.Name} Type: {type} Phase:{item.Status.Phase}";
var remessage = $"Namespace: {Namespace} Pod: {item.Metadata.Name} Type: {type} back to Phase:{item.Status.Phase}";
Console.WriteLine(message);
if (!item.Status.Phase.Equals("Running") && !item.Status.Phase.Equals("Succeeded"))
{ Console.WriteLine("==on watch event==");
await Notify(message);
Console.WriteLine("==on watch event==");
}
if ( type== WatchEventType.Modified && item.Status.Phase.Equals("Running") )
{ Console.WriteLine("==on watch event==");
await Notify(remessage);
Console.WriteLine("==on watch event==");
}
}))
{
Console.WriteLine("press ctrl + c to stop watching");
var ctrlc = new ManualResetEventSlim(false);
Console.CancelKeyPress += (sender, eventArgs) => ctrlc.Set();
ctrlc.Wait();
}
}
catch (System.Exception ex)
{
Console.Error.WriteLine($"An error happened Message: {ex.Message}", ex);
}
}
private static async Task Notify(string message)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://outlook.office.com");
var body = new { text = message };
var content = new StringContent(JsonConvert.SerializeObject(body));
var result = await client.PostAsync("https://outlook.office.com/webhook/xxxx/IncomingWebhook/xxx", content);
result.EnsureSuccessStatusCode();
}
}
For anyone looking for such tool, do try BotKube. It is built to send
Kubernetes events to messengers like Slack, Mattermost and Microsoft Teams. It also has features like custom filters
Implemented Auto Email sending scheduler using Quartz.net in Asp.Net MVC. The Code is working fine in VS IDE for sending mails based on set time period. while i am deploying in QA VM (IIS-10). The application is not sending emails
I follow few blogs and solution for setting up IIS 8/10 , But my application is not able send Auto Email after follow that.Below is the links
https://satvasolutions.com/job-scheduling-asp-mvc-quartz-scheduler/
https://github.com/quartznet/quartznet/issues/180
Please provide solution or guide to setup or something need to do diffrent way.
Here my code for Auto scheduler
public async static void Start()
{
IScheduler scheduler = await
StdSchedulerFactory.GetDefaultScheduler();
await scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailJob>().Build();
ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(1)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
)
.Build();
await scheduler.ScheduleJob(job, trigger);
}
note: "EmailJob" class will use to SMTP configuration and fetching data from Db and send mail.
After that,Will Call that method in global.asaxenter code here
protected void Application_Start()
{
JobScheduler.Start();
}
It's been working while runing in VS 2017 on local machine , But after published to IIS-10 the scheduler is not working.
Hi we are currently working on kendo UI Scheduler and wanting to make the scheduler real time using SignalR.
What we are trying to achieve is if 2 customers are viewing the scheduler at the same time and client 1 makes a booking the 2nd client will see that someone has booked that particular time slot so that double booking does not occur.
also if a client makes a booking on the scheduler then the admin will also see the booking in real time.
currently we have the scheduler inserting to the database with no problem, from there we want to broadcast the newly created booking to all others who are viewing the scheduler at that time.
can this be done? if so any ideas.
i can supply code to what we have done upto now if need required.
my thoughts are to broadcast the new scheduler booking in the ActionScript method then broadcast the new booking to clients from there.
public ActionResult Tasks_Create([DataSourceRequest]DataSourceRequest request, TaskViewModel task)
{
if (ModelState.IsValid)
{
using (var sampleDB = new SampleEntities())
{
//Create a new Task entity and set its properties from the posted TaskViewModel
var entity = new Task
{
TaskID = task.TaskID,
Title = task.Title,
Start = task.Start,
End = task.End,
Description = task.Description,
RecurrenceRule = task.RecurrenceRule,
RecurrenceException = task.RecurrenceException,
RecurrenceID = task.RecurrenceID,
IsAllDay = task.IsAllDay,
OwnerID = task.OwnerID
};
sampleDB.Tasks.Add(entity);
sampleDB.SaveChanges();
task.TaskID = entity.TaskID;
}
}
(i was thinking to broadcast the new booking here using signalr ????)
return Json(new[] { task }.ToDataSourceResult(request, ModelState));
}
Yes, it can be done (and broadcasting from your controller action is a reasonable approach). You'll probably want to create a group for people who are looking at the same data.
Take a look at this section in the docs on how to call client hub methods from non-hub classes.
I am building online auction application in asp.net mvc using EF code first, currently I am updating the latest bid amount polling via ajax every 5 seconds. is there any other way I can achieve the same
For example subscribing to a datarow which updates the UI element for any latest bid amount.
example:
Bid bid = _bidService.GetLatestBid(auctionId)
bid.Subscribe();
uielement.Update(bid.amount),
can I use SQLDependency and may be dotnet reactive extensions? any body has any sample code or solution?
Enable sql dependency on your database first.
Next, create SqlDependency from SqlCommand and convert events into observable using Observable.FromEventPattern.
sample code:
public class SqlDependencyObservable : ObservableBase<SqlNotificationEventArgs>
{
private readonly SqlCommand _command;
public SqlDependencyObservable(SqlCommand command)
{
_command = command;
}
protected override IDisposable SubscribeCore(IObserver<SqlNotificationEventArgs> observer)
{
SqlDependency dependency = new SqlDependency(_command);
return Observable.FromEventPattern<OnChangeEventHandler, SqlNotificationEventArgs>
(addHandler: handler => dependency.OnChange += handler, removeHandler: handler => dependency.OnChange -= handler)
.Select(i => i.EventArgs)
.Subscribe(observer);
}
}
I would like to cancel a task using a cancellation token as described here: http://msdn.microsoft.com/en-us/library/dd997396.aspx.
The only difference is that:
I would like to start a task when I browse to a specific controller/Action, and cancel the task(tokenSource.Cancel()) to be called when I LEAVE, browse away from that specific action (page) I'm currently on. How would i do it? Thanks
I figured it out.
I wrote a custom Attribute Filter that does this. Then in the code I have the following:
tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;
var taskRepository = UnityContainerSetup.Container.Resolve<ITaskRepository>();
taskRepository.GetTasksStatusAsync(siteId, tasksItem, ct); // ct is my cancellation token that I set to true => to cancel