I have the following code:
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailJob>().StoreDurably().WithIdentity("J_Email", "J_Mailing").Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("MailTrigger1", "T_Mail1")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(3)
.RepeatForever())
.Build();
ITrigger triggernew = TriggerBuilder.Create()
.WithIdentity("MailTrigger", "T_Mail")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(5)
.RepeatForever())
.Build();
scheduler.ScheduleJob(job,triggernew);
scheduler.ScheduleJob(job,trigger);
I am getting the following exception:
An unhandled exception of type 'Quartz.ObjectAlreadyExistsException'
occurred in Quartz.dll
Additional information: Unable to store Job: 'J_Mailing.J_Email',
because one already exists with this identification.
But I have been told that you can have multiple triggers of the same JOB. Maybe I am doing something wrong?
Add the Job to the Scheduler.
Then on the creation of the triggers, use ForJob.
The code below is tested.
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
//// scheduler.DeleteJob(new JobKey("J_Email"));
IJobDetail job = JobBuilder.Create<MyConcreteJob>().StoreDurably().WithIdentity("J_Email", "J_Mailing").Build();
scheduler.AddJob(job, true /* bool replace */ ); /* Add the given IJob to the Scheduler - with no associated ITrigger. */
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("MailTrigger1", "T_Mail1")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(3)
.RepeatForever())
.ForJob(job)
.Build();
ITrigger triggernew = TriggerBuilder.Create()
.WithIdentity("MailTrigger", "T_Mail")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(5)
.RepeatForever())
.ForJob(job)
.Build();
scheduler.ScheduleJob(triggernew);
scheduler.ScheduleJob(trigger);
scheduler.Start();
Related
I'm trying to perform the following code on a console application that uses Quarz.NET, but I got the following exception.
Here's the snippet of code
public Task AddSchedule(FlussoAnagraficaItem item)
{
if(this.scheduler == null) throw new Exception("scheduler is null, has the InitAsync method been invoked?");
var jobItemType = this.jobCreatorFactory.CreateJobFromAnagraficaFlussiItem(item);
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create(jobItemType)
.WithIdentity(item.Description, "sender")
.Build();
// Trigger the job to run now, and then repeat every 10 seconds
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity($"trigger_{item.Description}", "sender")
.StartNow().WithCronSchedule(item.Timespan)
.Build();
// Tell quartz to schedule the job using our trigger
return this.scheduler.ScheduleJob(job, trigger);
}
Where item.Timespan is "00 16 * * 5" , what's wrong?
Thanks
I am new to angulardart and I am working on mailer, but I am having an error that says:
dart_sdk.js:100398
EXCEPTION: Unsupported operation:
Platform._localHostname STACKTRACE: dart:sdk_internal
get localHostname package:mailer2/src/smtp/smtp_options.dart 4:25
new package:mailer2/src/smtp/helper_options.dart 12:24
new
package:DigitalHrSummit/src/components/homepagecomponent/homepage_component.dart
68:21 onSubmit
package:DigitalHrSummit/src/components/homepagecomponent/homepage_component.template.dart
1025:8 [_handle_click_287_0]
package:angular/src/core/linker/app_view.dart 602:29
src__core__linker__app_view_utils.appViewUtils.eventManager.zone.runGuarded.dart.fn
package:angular/src/core/zone/ng_zone.dart 134:16
parent.run.dart.fn dart:sdk_internal
run package:angular/src/core/zone/ng_zone.dart 131:18
[_run] dart:sdk_internal
runGuarded package:angular/src/core/zone/ng_zone.dart 302:22
runGuarded package:angular/src/core/linker/app_view.dart 601:37
event
Basically I just have the sample code that can be found here . I have my gmail username and password in the options variable.
I have the sample code inside my .dart component(homepage_component.dart)
...
import 'package:mailer2/mailer.dart';
...
class HomeComponent(){
void onSubmit(Map<String, dynamic> contactUsInfo) {
//Gmail account used to send email
var options = new GmailSmtpOptions()
..username = 'my-gmail-account'
..password = 'my-gmail-password';
// Create our email transport.
var emailTransport = new SmtpTransport(options);
// Create our mail/envelope.
var envelope = new Envelope()
..from = 'sender-email-here'
..recipients.add('recievers-mail-here')
//..bccRecipients.add('hidden#recipient.com')
..subject = 'Testing the Dart Mailer library'
//..attachments.add(new Attachment(file: new File('path/to/file')))
..text = 'This is a cool email message. Whats up?'
..html = '<h1>Test</h1><p>Hey!</p>';
// Email it.
emailTransport.send(envelope)
.then((envelope) => print('Email sent!'))
.catchError((e) => print('Error occurred: $e'));
}
}
Please help me guys. Thank you.
This library imports dart:io and therefore it isn't usable on the web.
I have a cron job which has multiple triggers all triggers have been scheduled for the interval of lets say 5 min, now I need to update job data map at runtime, for that I need that particular trigger which requires to update but I am failing to get that particular trigger, I am doing something like that
String cronExpression = "0 0/5 * * * ?"
String triggername = "mytrigger" + System.currentTimeMillis()
JobDataMap jobDataMap = new JobDataMap([host: config.host, port: config.port, username: config.username, password: config.password])
CronTrigger trigger = TriggerBuilder.newTrigger()
.withIdentity(triggername)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).usingJobData(jobDataMap)
.build()
MyJob.schedule(trigger)
Any idea how can I get that particular trigger which I have to update?
Try something like that:
List<Trigger> triggers = quartzScheduler.jobGroupNames.collect {
quartzScheduler.getJobKeys(GroupMatcher.groupEquals(it)).collect {
quartzScheduler.getTriggersOfJob(it)
}
}.flatten()
It will return all your scheduled triggers. After get them you can do what you need in JobDataMap.
I suggest use a familiar trigger identity, it make easier to find a specific one at runtime.
I saved the trigger name in database, and when I need to update that trigger I simply fetch that trigger like this:
TriggerKey triggerKey = new TriggerKey(triggerName_from_db);
try {
Trigger trigger = quartzScheduler.getTrigger(triggerKey)
if (trigger?.key?.name) {
trigger.jobDataMap['host'] = config.host
trigger.jobDataMap['port'] = config.port
trigger.jobDataMap['username'] = config.username
trigger.jobDataMap['password'] = config.password
}
quartzScheduler.rescheduleJob(triggerKey, trigger)
}catch (SchedulerException ex) {
log.error ex.toString()
}
I have what should be a simple task. I create a new job, make if durable and add add using the IScheduler.AddJob method. The job is registered but for the life of me I can not figure how to assign triggers to it.
This is from the tutorial:
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(DumbJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeHourlyTrigger();
// start on the next even hour
trigger.StartTime = TriggerUtils.GetEvenHourDate(DateTime.UtcNow);
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger);
I Am trying to use Quartz.Net so as to Schedule Jobs Within a Windows Service that I developped.
I included the following code on the Onstart Method, scheduler is a Class attribute
private readonly IScheduler scheduler;
logger = LogManager.GetLogger(typeof (TelegestionService));
scheduler = new StdSchedulerFactory().GetScheduler();
var job = new JobDetail("job1", "group1", typeof (HelloJob));
var trigger = new SimpleTrigger("trigger1", "group1", runTime);
scheduler.ScheduleJob(job, trigger);
This works fine for me. I got the Job running.
Now I'am trying to make the scheduler embedded remotely accessible, based en Example12 in the Quartz source Examples (the Console Server/Client works fine).
var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "RemoteServer";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";
scheduler = new StdSchedulerFactory(properties).GetScheduler();
The service starts correctly and so does the scheduler but i cannot remotely schedule the Job using a Console/Winform Client (Connection refused).
I checked the LISTENING ports on my server using SysInternals TcpView and I cannot find the 555 port specified above.
Am suspecting an issue related to .Net Remoting but cannot figure out how to resolve this.
Any ideas ?
Thanks in advance.
could use http://topshelf-project.com/ to host Scheduler which will provide hostFactory and using that could shelf host via HttpSelfHostServer, http is better as you could invoke job via controller. sample code as below
hope this helps.
using System;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.SelfHost;
using Topshelf;
class Program
{
static void Main(string[] args)
{
HostFactory.Run(hostConfigurator =>
{
if (!Uri.TryCreate("http://localhost:8080", UriKind.RelativeOrAbsolute, out var hostname))
{
throw new ConfigurationErrorsException($"Could not uri");
}
var serviceName = "my service";
var hostConfiguration = new HttpSelfHostConfiguration(hostname);
hostConfiguration.Routes.MapHttpRoute("API", "{controller}/{action}/{id}", (object)new
{
id = RouteParameter.Optional
});
var httpSelfHostServer = new HttpSelfHostServer(hostConfiguration);
// Impl.Scheduler would be your implementation of scheduler
hostConfigurator.Service<Impl.Scheduler>(s =>
{
s.ConstructUsing(name => new Impl.Scheduler());
s.WhenStarted(tc =>
{
tc.Start();
httpSelfHostServer.OpenAsync().Wait();
});
s.WhenStopped(tc =>
{
tc.Stop();
//dispose scheduler implementation if using IOC container
httpSelfHostServer.CloseAsync().Wait();
});
});
hostConfigurator.RunAsLocalSystem();
hostConfigurator.SetDescription(serviceName);
hostConfigurator.SetDisplayName(serviceName);
hostConfigurator.SetServiceName(serviceName);
});
}
}