private static ScheduledTask NewTask <T>(ScheduledProducerSettings settings, object instance = null) { Type type = typeof(T); HandlerInfo handlerInfo = new HandlerInfo(type.Namespace, type.Name); if (instance != null) { handlerInfo.Instance = JsonConvert.SerializeObject(instance); } ScheduledTask scheduledTask = new ScheduledTask { Handler = JsonConvert.SerializeObject(handlerInfo) }; settings.ProvisionTask(scheduledTask); return(scheduledTask); }
public ScheduledProducer(ScheduledProducerSettings settings = null) { _settings = settings ?? new ScheduledProducerSettings(); _schedulers = new ConcurrentDictionary <int, TaskScheduler>(); _factories = new ConcurrentDictionary <TaskScheduler, TaskFactory>(); _pending = new ConcurrentDictionary <Handler, HandlerMethods>(); _cancel = new CancellationTokenSource(); _threads = _settings.Concurrency; // polling thread Background = new BackgroundThreadProducer <IEnumerable <ScheduledTask> >(); Background.Attach(WithPendingTasks); Background.AttachBacklog(WithOverflowTasks); Background.AttachUndeliverable(WithFailedTasks); // maintenance thread Maintenance = new BackgroundThreadProducer <IEnumerable <ScheduledTask> >(); Maintenance.Attach(WithHangingTasks); Maintenance.AttachBacklog(WithHangingTasks); Maintenance.AttachUndeliverable(WithHangingTasks); }