示例#1
0
 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);
 }
示例#2
0
        /**
         * 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>();
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }