private bool RegisterExecutor(ScheduledTaskExecutor texec) { if (texec.Job is Reminder rem) { Log.Debug("Attempting to register reminder {ReminderId} in channel {Channel} @ {ExecutionTime}", rem.Id, rem.ChannelId, rem.ExecutionTime); if (!this.reminders.TryAdd(texec.Id, texec)) { if (!rem.IsRepeating) { Log.Warning("Reminder {Id} already exists in the collection for user {UserId}", texec.Id, rem.UserId); } return(false); } } else { Log.Debug("Attempting to register guild task {ReminderId} @ {ExecutionTime}", texec.Id, texec.Job.ExecutionTime); if (!this.tasks.TryAdd(texec.Id, texec)) { Log.Warning("Guild task {Id} already exists in the collection for user {UserId}", texec.Id); return(false); } } return(true); }
/** * Create a new scheduled task service. The thread pool size is from the WorldWind configuration file property * {@link AVKey#TASK_POOL_SIZE}. */ public BasicScheduledTaskService() { Integer poolSize = Configuration.getIntegerValue(AVKey.TASK_POOL_SIZE, DEFAULT_POOL_SIZE); // this.executor runs the tasks, each in their own thread this.executor = new ScheduledTaskExecutor(poolSize); // this.activeTasks holds the list of currently executing tasks this.activeTasks = new ConcurrentLinkedQueue <Runnable>(); }
private ScheduledTaskExecutor CreateTaskExecutor(ScheduledTask task) { var texec = new ScheduledTaskExecutor(this.client, this.lcs, this.async, task); texec.OnTaskExecuted += this.UnscheduleAsync; if (this.RegisterExecutor(texec) && !task.IsExecutionTimeReached) { texec.ScheduleExecution(); } return(texec); }
private async Task <bool> RegisterDbTaskAsync(ScheduledTask task) { ScheduledTaskExecutor texec = this.CreateTaskExecutor(task); if (task.IsExecutionTimeReached) { await texec.HandleMissedExecutionAsync(); await this.UnscheduleAsync(task); return(false); } return(true); }