/// <summary> /// Adds the task. /// </summary> /// <typeparam name="TTransportInit">The type of the transport initialize.</typeparam> /// <param name="jobQueueCreation">The job queue creation.</param> /// <param name="name">The name.</param> /// <param name="queueConnection">Queue and connection information.</param> /// <param name="schedule">The schedule.</param> /// <param name="autoRun">if set to <c>true</c> [automatic run].</param> /// <param name="window">The window.</param> /// <param name="actionToRun">The action to run.</param> /// <param name="expressionToRun">The expression to run.</param> /// <param name="route">The route.</param> /// <param name="rawExpression">if set to <c>true</c> this expression will not be serialized. This will fail unless an in-process queue is being used.</param> /// <param name="producerConfiguration">The producer configuration.</param> /// <returns></returns> /// <exception cref="JobSchedulerException">Cannot add a task after Shutdown has been called.</exception> private ScheduledJob AddTaskImpl <TTransportInit>( IJobQueueCreation jobQueueCreation, string name, QueueConnection queueConnection, IJobSchedule schedule, bool autoRun, TimeSpan window, Expression <Action <IReceivedMessage <MessageExpression>, IWorkerNotification> > actionToRun, LinqExpressionToRun expressionToRun, string route, bool rawExpression, Action <QueueProducerConfiguration> producerConfiguration = null) where TTransportInit : ITransportInit, new() { Guard.NotNull(() => schedule, schedule); Guard.NotNullOrEmpty(() => name, name); ScheduledJob job; lock (_lockTasks) { if (IsShuttingDown) { throw new JobSchedulerException("Cannot add a task after Shutdown has been called."); } if (_tasks.ContainsKey(name)) { RemoveJob(name); } if (expressionToRun != null) { job = new ScheduledJob(this, name, schedule, _jobQueue.Get <TTransportInit>(jobQueueCreation, queueConnection, producerConfiguration), expressionToRun, _getTime.Create(), route) { Window = window, IsAttached = true }; _tasks.Add(name, job); } else { job = new ScheduledJob(this, name, schedule, _jobQueue.Get <TTransportInit>(jobQueueCreation, queueConnection, producerConfiguration), actionToRun, _getTime.Create(), route, rawExpression) { Window = window, IsAttached = true }; _tasks.Add(name, job); } } job.OnException += TaskOnOnException; job.OnEnQueue += JobOnOnEnQueue; job.OnNonFatalFailureEnQueue += JobOnOnNonFatalFailureEnQueue; if (autoRun) { job.StartSchedule(); } return(job); }
/// <summary> /// Gets all jobs. /// </summary> /// <returns></returns> public IEnumerable <IScheduledJob> GetAllJobs() { lock (_lockTasks) { // could be one line of linq, but eh, this is cheaper var tasks = new ScheduledJob[_tasks.Count]; var i = 0; foreach (var t in _tasks) { tasks[i] = t.Value; i++; } return(tasks); } }
internal PendingEvent(DateTimeOffset scheduledTime, ScheduledJob job, int runId) { ScheduledTime = scheduledTime; Job = job; RunId = runId; }