Example #1
0
        public TaskInfo Dequeue()
        {
            var jsonString = Backend.Dequeue();
            var taskInfo   = JsonTaskInfoSerializer.Deserialize(jsonString);

            return(taskInfo);
        }
Example #2
0
        public Tuple <string, TaskInfo> SafeDequeue()
        {
            var jsonString = Backend.Dequeue();
            var taskInfo   = JsonTaskInfoSerializer.Deserialize(jsonString);

            return(Tuple.Create(jsonString, taskInfo));
        }
Example #3
0
        private void RestoreScheduledTasksFromStorage()
        {
            var serializer     = new JsonTaskInfoSerializer();
            var scheduledTasks = _taskQueue.Backend.GetList(ScheduleBackupKey)
                                 .Select(s => serializer.Deserialize <TaskSchedule>(s)).ToList();

            foreach (var scheduledTask in scheduledTasks)
            {
                _scheduledTasks[scheduledTask.TaskKey] = scheduledTask;
            }
        }
Example #4
0
        public async Task <TaskInfo> Dequeue()
        {
            var jsonString = await Backend.Dequeue();

            if (jsonString == null)
            {
                return(null);
            }

            var taskInfo = JsonTaskInfoSerializer.Deserialize(jsonString);

            return(taskInfo);
        }
Example #5
0
        /// <summary>
        /// Returns the serialized TaskInfo as well as deserialized so that the serialized value can later
        /// be removed from the backing queue.
        /// </summary>
        /// <returns></returns>
        public async Task <Tuple <string, TaskInfo> > SafeDequeue()
        {
            var jsonString = await Backend.Dequeue();

            if (jsonString == null)
            {
                return(Tuple.Create <string, TaskInfo>(null, null));
            }

            var taskInfo = JsonTaskInfoSerializer.Deserialize(jsonString);

            return(Tuple.Create(jsonString, taskInfo));
        }
Example #6
0
        internal async Task <TaskInfo> Dequeue()
        {
            var jsonString = await Backend.Dequeue(Config.QueueName);

            if (jsonString == null)
            {
                return(null);
            }

            var taskInfo = JsonTaskInfoSerializer.Deserialize(jsonString);

            taskInfo.UnconvertTypeArgs();
            return(taskInfo);
        }
Example #7
0
        /// <summary>
        /// Returns the serialized TaskInfo as well as deserialized so that the serialized value can later
        /// be removed from the backing queue.
        /// </summary>
        /// <returns></returns>
        public async Task <(string, TaskInfo)> SafeDequeue()
        {
            var jsonString = await Backend.Dequeue(Config.QueueName);

            if (jsonString == null)
            {
                return(null, null);
            }

            var taskInfo = JsonTaskInfoSerializer.Deserialize(jsonString);

            taskInfo.UnconvertTypeArgs();
            return(jsonString, taskInfo);
        }
Example #8
0
        public async Task <RecurringTask> GetRecurringTask(string taskKey)
        {
            var serializedRecurringTask = await _taskQueue.Backend.GetMapField(ScheduledTasksMapKey,
                                                                               $"serializedRecurringTask::{taskKey}");

            if (string.IsNullOrEmpty(serializedRecurringTask))
            {
                return(null);
            }

            var recurringTask = JsonTaskInfoSerializer.Deserialize <RecurringTask>(serializedRecurringTask);

            return(recurringTask);
        }
Example #9
0
        private async Task RescheduleRecurringTasks()
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            RecurringTask recurringTask;
            long          nextRunTimestamp;

            if (LoadedRescheduleRecurringTasksScript == null)
            {
                LoadedRescheduleRecurringTasksScript = await _taskQueue.Backend.LoadLuaScript(LuaScriptToRescheduleRecurringTask());
            }

            var serializedRecurringTasks = (await _taskQueue.Backend
                                            .DequeueBatch(RecurringTaskRescheduleQueueKey)).ToArray();

            if (serializedRecurringTasks.Length == 0)
            {
                return;
            }

            var args = new List <RedisValue>();

            foreach (var serializedRecurringTask in serializedRecurringTasks)
            {
                recurringTask    = JsonTaskInfoSerializer.Deserialize <RecurringTask>(serializedRecurringTask);
                nextRunTimestamp = recurringTask.GetNextRunTimestamp(DateTime.UtcNow);

                args.Add((RedisValue)recurringTask.TaskKey);
                args.Add((RedisValue)nextRunTimestamp);
            }

            await _taskQueue.Backend.RunLuaScript(LoadedRescheduleRecurringTasksScript,
                                                  new [] {
                (RedisKey)ScheduledTasksOrderedSetKey,
                (RedisKey)ScheduledTasksMapKey,
            },
                                                  args.ToArray());


            var profile = $"PROFILE {nameof(RescheduleRecurringTasks)}: {sw.ElapsedMilliseconds}";
            // Console.WriteLine(profile);
        }
Example #10
0
        public void ItPersistsPropertiesWhenSerializedAndDeserialized()
        {
            var taskInfos = new[] {
                GetTestTask(() => TestMethod1("hello world")),
                GetTestTask(() => TestMethod2())
            };

            foreach (var taskInfo in taskInfos)
            {
                var serializedTaskInfo   = JsonTaskInfoSerializer.Serialize(taskInfo);
                var deserializedTaskInfo = JsonTaskInfoSerializer.Deserialize <TaskInfo>(serializedTaskInfo);

                deserializedTaskInfo.Id.Should().Be(taskInfo.Id);
                deserializedTaskInfo.AssemblyName.Should().Be(taskInfo.AssemblyName);
                deserializedTaskInfo.TypeName.Should().Be(taskInfo.TypeName);
                deserializedTaskInfo.MethodName.Should().Be(taskInfo.MethodName);
                deserializedTaskInfo.ReturnType.Should().Be(taskInfo.ReturnType);
                deserializedTaskInfo.Args.ShouldAllBeEquivalentTo(taskInfo.Args);
                deserializedTaskInfo.CreatedAtUtc.Should().Be(taskInfo.CreatedAtUtc);

                deserializedTaskInfo.IsEquivalent(taskInfo).Should().BeTrue();
            }
        }
Example #11
0
        public void ItPersistsPropertiesWhenSerializedAndDeserialized()
        {
            var taskKey = $"{nameof(ItPersistsPropertiesWhenSerializedAndDeserialized)}::{Guid.NewGuid().ToString()}";

            var testTask = GetTestTask(() =>
                                       Console.WriteLine(nameof(ItPersistsPropertiesWhenSerializedAndDeserialized)));

            var recurringTasks = new [] {
                new RecurringTask(testTask, TimeSpan.FromMinutes(5), taskKey),
                new RecurringTask(testTask, "* * * * * *", taskKey)
            };

            foreach (var recurringTask in recurringTasks)
            {
                var serializedRecurringTask   = JsonTaskInfoSerializer.Serialize(recurringTask);
                var deserializedRecurringTask = JsonTaskInfoSerializer.Deserialize <RecurringTask>(serializedRecurringTask);

                deserializedRecurringTask.StartTime.Should().Be(recurringTask.StartTime);
                deserializedRecurringTask.TaskKey.Should().Be(recurringTask.TaskKey);
                deserializedRecurringTask.Interval.Should().Be(recurringTask.Interval);
                deserializedRecurringTask.Crontab.Should().Be(recurringTask.Crontab);
                deserializedRecurringTask.TaskInfo.IsEquivalent(recurringTask.TaskInfo).Should().BeTrue();
            }
        }