public async Task CreateReminder(string command, JobPeriod period)
        {
            await AddNewBackgroundJob(command, period, BackgroundJobType.Reminder);

            var primaryKey = this.GetPrimaryKey(out var deviceId);

            await this.RegisterOrUpdateReminder(primaryKey.ToString(), TimeSpan.FromMinutes(period.Period),
                                                TimeSpan.FromMinutes(period.Period));
        }
        public async Task CreateTimer(string command, JobPeriod period)
        {
            await AddNewBackgroundJob(command, period, BackgroundJobType.Timer);

            _timer = this.RegisterTimer(async(state) =>
            {
                if (DateTime.Now > this.State.StartTime)
                {
                    if (this.State.IsStopped)
                    {
                        this._timer.Dispose();
                        this.State.JobStatus = JobStatus.Stopped;
                        await this.WriteStateAsync();
                        return;
                    }

                    await HandleBackgroundJob();
                }
            }, this.State, TimeSpan.FromSeconds(period.Period), TimeSpan.FromSeconds(period.Period));
        }
        private async Task AddNewBackgroundJob(string command, JobPeriod period, BackgroundJobType type)
        {
            this.GetPrimaryKey(out var deviceId);

            var backgroundJob = new BackgroundJob()
            {
                Command   = command,
                JobType   = type,
                DeviceId  = deviceId,
                StartTime = period.StartTime,
                EndTime   = period.EndTime,
                Period    = period.Period,
                JobStatus = JobStatus.Pending
            };

            this.State = backgroundJob;

            await this.DataContext.AddAsync(this.State);

            await this.WriteStateAsync();
        }