예제 #1
0
 public void MergeFrom(Schedule other)
 {
     if (other == null)
     {
         return;
     }
     if (other.Name.Length != 0)
     {
         Name = other.Name;
     }
     if (other.DisplayName.Length != 0)
     {
         DisplayName = other.DisplayName;
     }
     if (other.Description.Length != 0)
     {
         Description = other.Description;
     }
     if (other.State != global::Google.Cloud.Notebooks.V1.Schedule.Types.State.Unspecified)
     {
         State = other.State;
     }
     if (other.CronSchedule.Length != 0)
     {
         CronSchedule = other.CronSchedule;
     }
     if (other.TimeZone.Length != 0)
     {
         TimeZone = other.TimeZone;
     }
     if (other.createTime_ != null)
     {
         if (createTime_ == null)
         {
             CreateTime = new global::Google.Protobuf.WellKnownTypes.Timestamp();
         }
         CreateTime.MergeFrom(other.CreateTime);
     }
     if (other.updateTime_ != null)
     {
         if (updateTime_ == null)
         {
             UpdateTime = new global::Google.Protobuf.WellKnownTypes.Timestamp();
         }
         UpdateTime.MergeFrom(other.UpdateTime);
     }
     if (other.executionTemplate_ != null)
     {
         if (executionTemplate_ == null)
         {
             ExecutionTemplate = new global::Google.Cloud.Notebooks.V1.ExecutionTemplate();
         }
         ExecutionTemplate.MergeFrom(other.ExecutionTemplate);
     }
     recentExecutions_.Add(other.recentExecutions_);
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
예제 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (DisplayName.Length != 0)
            {
                hash ^= DisplayName.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (State != global::Google.Cloud.Notebooks.V1.Schedule.Types.State.Unspecified)
            {
                hash ^= State.GetHashCode();
            }
            if (CronSchedule.Length != 0)
            {
                hash ^= CronSchedule.GetHashCode();
            }
            if (TimeZone.Length != 0)
            {
                hash ^= TimeZone.GetHashCode();
            }
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (updateTime_ != null)
            {
                hash ^= UpdateTime.GetHashCode();
            }
            if (executionTemplate_ != null)
            {
                hash ^= ExecutionTemplate.GetHashCode();
            }
            hash ^= recentExecutions_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #3
0
        public async Task <CommandResult> Handle(CreateExecutionScheduleCommand request, CancellationToken cancellationToken)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            ExecutionSchedule schedule = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionSchedule>(st => st.Name == request.Name);

            if (schedule != null)
            {
                throw new InvalidExecutionScheduleException("Execution Schedule with name " + request.Name + " is invalid.");
            }

            ExecutionTemplate template = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionTemplate>(st => st.Name == request.ExecutionTemplateName);

            if (template == null)
            {
                throw new InvalidExecutionScheduleException("Execution Template with name " + request.ExecutionTemplateName + " is invalid.");
            }

            foreach (var scheduleString in request.Schedule)
            {
                var isValid = SchedulerUtility.IsValidScheduleString(scheduleString);
                if (!isValid)
                {
                    throw new InvalidExecutionScheduleException("Schedule " + scheduleString + " is invalid.");
                }
            }

            var executionSchedule = new ExecutionSchedule(
                Guid.NewGuid(),
                request.Name,
                request.ExecutionTemplateName,
                request.Description,
                request.CreatedBy,
                request.Schedule,
                SchedulerUtility.NextOccurence(request.Schedule)
                );

            var executionScheduleResponse = await _node.Handle(new AddShardWriteOperation()
            {
                Data             = executionSchedule,
                WaitForSafeWrite = true,
                Operation        = ConsensusCore.Domain.Enums.ShardOperationOptions.Create
            });

            if (request.RunImmediately)
            {
                await _mediator.Send(new ExecuteExecutionTemplateCommand()
                {
                    CreatedBy           = request.CreatedBy,
                    ExecutionScheduleId = executionSchedule.Id,
                    Name = executionSchedule.ExecutionTemplateName
                });
            }


            stopwatch.Stop();
            return(new CommandResult <ExecutionSchedule>()
            {
                ObjectRefId = executionSchedule.Id.ToString(),
                ElapsedMs = stopwatch.ElapsedMilliseconds,
                Type = CommandResultTypes.Create,
                Result = executionSchedule
            });
        }