private void StartJob(JobDefinition job)
		{
			this.EventReporter.Trace("Creating job: " + job.JobName);
			if(job.Schedule is JobCronSchedule)
			{
			}
			else if(job.Schedule is JobSimpleSchedule) 
			{
				var type = this.TypeLoader.LoadType(job.AssemblyName, job.ClassName);
				var genericJobWrapperType = typeof(JobWrapper<,>);
				var combinedJobType = genericJobWrapperType.MakeGenericType(type);
				var jobDetail = new JobDetailImpl(job.JobName, combinedJobType);
				var simpleSchedule = (JobSimpleSchedule)job.Schedule;
				ITrigger trigger;
				if (simpleSchedule.DelayStartMinutes != 0)
				{
					trigger = new SimpleTriggerImpl(job.JobName + "Trigger", DateBuilder.FutureDate(simpleSchedule.DelayStartMinutes,IntervalUnit.Minute), null, SimpleTriggerImpl.RepeatIndefinitely, TimeSpan.FromMinutes(simpleSchedule.IntervalMinutes));
				}
				else
				{
					trigger = new SimpleTriggerImpl(job.JobName + "Trigger", null, SimpleTriggerImpl.RepeatIndefinitely, TimeSpan.FromMinutes(simpleSchedule.IntervalMinutes));
				}
				this.Scheduler.ScheduleJob(jobDetail, trigger);
			}
			this.EventReporter.Trace("Done Creating " + job.JobName);
		}
Example #2
0
		public JobDefinition CreateCronJob(string jobName, Guid jobGuid, string assemblyName, string className, string cronScheduleExpression)
		{
			if(jobGuid == Guid.Empty)
			{
				jobGuid = Guid.NewGuid();
			}
			var item = new JobDefinition
			{
				JobName = jobName,
				JobGuid = jobGuid,
				AssemblyName = assemblyName,
				ClassName = className, 
				Schedule  = new JobCronSchedule
				{
					CronScheduleExpression = cronScheduleExpression
				}
			};
			this.DocumentSession.Store(item);
			this.DocumentSession.SaveChanges();
			return item;
		}
Example #3
0
		public JobDefinition CreateSimpleJob(string jobName, Guid jobGuid, string assemblyName, string className, int intervalMinutes, int delayStartMinutes)
		{
			if(jobGuid == Guid.Empty)
			{
				jobGuid = Guid.NewGuid();
			}
			var item = new JobDefinition
			{
				JobName = jobName,
				JobGuid = jobGuid,
				AssemblyName = assemblyName,
				ClassName = className,
				Schedule = new JobSimpleSchedule
				{
					IntervalMinutes = intervalMinutes,
					DelayStartMinutes = delayStartMinutes
				}
			};
			this.DocumentSession.Store(item);
			this.DocumentSession.SaveChanges();
			return item;
		}
Example #4
0
		public void EnsureConfiguration(JobDefinition jobDefinition)
		{
			if (jobDefinition.Configuration == null)
			{
				var jobType = this.TypeLoader.LoadType(jobDefinition.AssemblyName, jobDefinition.ClassName);
				if (jobType != null)
				{
					var configType = this.GetJobConfigurationType(jobType);
					if (configType != null && configType != typeof(NullJobConfiguration))
					{
						jobDefinition.Configuration = (JobConfigurationBase)Activator.CreateInstance(configType);
						this.DocumentSession.SaveChanges();
					}
				}
			}
		}
Example #5
0
		private Type TryGetQueueDataType(JobDefinition jobDefinition)
		{
			Type queueDataType = null;
			var jobType = this.TypeLoader.LoadType(jobDefinition.AssemblyName, jobDefinition.ClassName);
			//var jobAssembly = Assembly.Load(jobDefinition.AssemblyName.Replace(".dll", ""));
			//var jobType = jobAssembly.GetType(jobDefinition.ClassName);
			var queueInterface = jobType.GetInterfaces().SingleOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(QueueJobBase<,>));
			if (queueInterface != null)
			{
				queueDataType = queueInterface.GetGenericArguments()[0];
			}
			return queueDataType;
		}
Example #6
0
		public IQueryable<JobData> GetJobDataQueue(JobDefinition jobDefinition)
		{
			var queueType = TryGetQueueDataType(jobDefinition);
			if(queueType == null)
			{
				throw new Exception(jobDefinition.JobName + " does not have a queue data type");
			}
			return GetJobDataQueue(queueType);
		}
Example #7
0
		private void StartJob(JobDefinition jobDefinition, bool runNow = false)
		{
			this.EventReporter.Trace("Creating " + jobDefinition.JobName);
			var jobType = this.TypeLoader.LoadType(jobDefinition.AssemblyName, jobDefinition.ClassName);
			var configType = jobType.BaseType.GetGenericArguments()[0];
			var wrapperType = typeof(JobWrapper<,>).MakeGenericType(jobType, configType);
			var jobDetail = new JobDetailImpl(jobDefinition.JobName, wrapperType);
			jobDetail.JobDataMap.Add("Configuration", jobDefinition.Configuration);

			if (runNow)
			{
				var trigger = new SimpleTriggerImpl(jobDefinition.JobName + "Trigger", DateBuilder.FutureDate(0, IntervalUnit.Minute), null, 1, TimeSpan.FromMinutes(int.MaxValue));
				this.Scheduler.ScheduleJob(jobDetail, trigger);
			}
			else if (jobDefinition.Schedule is JobSimpleSchedule)
			{
				var schedule = (JobSimpleSchedule)jobDefinition.Schedule;
				var trigger = new SimpleTriggerImpl(jobDefinition.JobName + "Trigger", DateBuilder.FutureDate(schedule.DelayStartMinutes, IntervalUnit.Minute), null, SimpleTriggerImpl.RepeatIndefinitely, TimeSpan.FromMinutes(schedule.IntervalMinutes));
				this.Scheduler.ScheduleJob(jobDetail, trigger);
			}
			else if (jobDefinition.Schedule is JobCronSchedule)
			{
				var schedule = (JobCronSchedule)jobDefinition.Schedule;
				var trigger = new CronTriggerImpl(jobDefinition.JobName + "Trigger", jobDefinition.JobName + "Group", schedule.CronScheduleExpression);
				this.Scheduler.ScheduleJob(jobDetail, trigger);
			}
			this.EventReporter.Trace("Done Creating " + jobDefinition.JobName);
		}