/// <summary> /// Gets end time schedule. /// </summary> /// <param name="recurrence">Job recurrence values.</param> /// <returns>End time in string.</returns> internal static string GetEndSchedule(JobRecurrence recurrence) { if (recurrence == null) { return("Run once"); } else { if (recurrence.Count == null && recurrence.EndTime == null) { return("None"); } else if (recurrence.Count != null && recurrence.EndTime != null) { return("Until " + recurrence.Count + " executions. Or on " + recurrence.EndTime + " whichever occurs first."); } else if (recurrence.Count != null) { return("Until " + recurrence.Count + " executions."); } else { return("On " + recurrence.EndTime + "."); } } }
/// <summary> /// Converts recurrence to string. /// </summary> /// <param name="recurrence"></param> /// <returns></returns> internal static string ConvertRecurrenceToString(JobRecurrence recurrence) { if (recurrence == null) { return(null); } return("Every " + recurrence.Interval + " " + recurrence.Frequency.ToString() + "s"); }
/// <summary> /// Gets job recurrence. /// </summary> /// <param name="jobRecurrenceParams">Job recurrence properties specified via PowerShell.</param> /// <returns>JobRecurrence object.</returns> private JobRecurrence GetJobRecurrence(PSJobRecurrenceParams jobRecurrenceParams) { if (jobRecurrenceParams != null && (jobRecurrenceParams.Interval != null || jobRecurrenceParams.ExecutionCount != null || !string.IsNullOrWhiteSpace(jobRecurrenceParams.Frequency) || jobRecurrenceParams.EndTime != null)) { var jobRecurrence = new JobRecurrence() { Count = jobRecurrenceParams.ExecutionCount ?? default(int?), Interval = jobRecurrenceParams.Interval ?? default(int?), EndTime = jobRecurrenceParams.EndTime ?? default(DateTime?), Frequency = jobRecurrenceParams.Frequency.GetValueOrDefaultEnum <RecurrenceFrequency?>(defaultValue: null) }; return(jobRecurrence); } return(null); }
public ScheduledAutoTest UpdateJob(string name, DateTime startTime, int recurEveryXHour) { var existingjob = _schedulerClient.Jobs.Get(name); var jobRecurrence = new JobRecurrence() { EndTime = DateTime.Now.AddYears(1), Frequency = JobRecurrenceFrequency.Hour, Interval = recurEveryXHour }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Recurrence = jobRecurrence, StartTime = startTime, Action = existingjob.Job.Action }; var result = _schedulerClient.Jobs.CreateOrUpdate(name, jobCreateOrUpdateParameters); _needRefresh = true; return(GetFromJob(result.Job)); }
private ScheduledAutoTest Create(string name, int testplanId, DateTime startTime, string qName, int recurEveryXHour = 24) { name = name.Replace(" ", ""); var action = new JobAction() { Type = JobActionType.StorageQueue, QueueMessage = new JobQueueMessage { Message = GetRegTestBody(testplanId), QueueName = qName, StorageAccountName = _storageAccountName, SasToken = _sasToken } }; var jobRecurrence = new JobRecurrence() { EndTime = DateTime.Now.AddYears(1), Frequency = JobRecurrenceFrequency.Hour, Interval = recurEveryXHour }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Action = action, Recurrence = jobRecurrence, StartTime = startTime }; var result = _schedulerClient.Jobs.CreateOrUpdate(name, jobCreateOrUpdateParameters); _needRefresh = true; return(GetFromJob(result.Job)); }
/// <summary> /// Converts recurrence to string. /// </summary> /// <param name="recurrence"></param> /// <returns></returns> internal static string ConvertRecurrenceToString(JobRecurrence recurrence) { if (recurrence == null) { return null; } return "Every " + recurrence.Interval + " " + recurrence.Frequency.ToString() + "s"; }
/// <summary> /// Gets end time schedule. /// </summary> /// <param name="recurrence">Job recurrence values.</param> /// <returns>End time in string.</returns> internal static string GetEndSchedule(JobRecurrence recurrence) { if (recurrence == null) { return "Run once"; } else { if (recurrence.Count == null && recurrence.EndTime == null) { return "None"; } else if (recurrence.Count != null && recurrence.EndTime != null) { return "Until " + recurrence.Count + " executions. Or on " + recurrence.EndTime + " whichever occurs first."; } else if (recurrence.Count != null) { return "Until " + recurrence.Count + " executions."; } else { return "On " + recurrence.EndTime + "."; } } }
private static JobDefinition CreateJobDefinition(String connection, String message, JobRecurrence recurrence) { var jobDefinition = new JobDefinition(); jobDefinition.Properties = new JobProperties(); jobDefinition.Properties.Action = new JobAction(); jobDefinition.Properties.Action.QueueMessage = new StorageQueueMessage(); jobDefinition.Properties.Action.Type = JobActionType.StorageQueue; jobDefinition.Properties.Action.QueueMessage.QueueName = "scheduler"; jobDefinition.Properties.Action.QueueMessage.StorageAccount = Methods.GetStorageAccountName(connection); jobDefinition.Properties.Action.QueueMessage.SasToken = Methods.GetQueueSasToken(connection); jobDefinition.Properties.Action.QueueMessage.Message = message; jobDefinition.Properties.StartTime = DateTime.UtcNow.AddYears(-1); jobDefinition.Properties.Recurrence = recurrence; return(jobDefinition); }
/// <summary> /// Create a job. /// </summary> /// <param name="createJobParams">Job properties entered via powershell.</param> /// <returns>The Job definition.</returns> public PSSchedulerJobDefinition CreateJob(PSJobParams createJobParams) { if (string.IsNullOrWhiteSpace(createJobParams.ResourceGroupName)) { throw new PSManagement.PSArgumentNullException(paramName: "ResourceGroupName"); } if (string.IsNullOrWhiteSpace(createJobParams.JobCollectionName)) { throw new PSManagement.PSArgumentNullException(paramName: "JobCollectionName"); } if (string.IsNullOrWhiteSpace(createJobParams.JobName)) { throw new PSManagement.PSArgumentNullException(paramName: "JobName"); } if (!DoesResourceGroupExists(createJobParams.ResourceGroupName)) { throw new PSManagement.PSArgumentException(Resources.SchedulerInvalidResourceGroup); } IList <JobCollectionDefinition> jobCollection = ListJobCollection(createJobParams.ResourceGroupName, createJobParams.JobCollectionName); if (jobCollection == null || jobCollection.Count < 1) { throw new PSManagement.PSInvalidOperationException(string.Format(Resources.JobCollectionDoesnotExist, createJobParams.JobCollectionName, createJobParams.ResourceGroupName)); } else { if (JobExists(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, createJobParams.JobName)) { throw new PSManagement.PSArgumentException(string.Format(Resources.SchedulerExistingJob, createJobParams.JobName, createJobParams.JobCollectionName)); } IList <JobDefinition> listOfJobs = ListJobs(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, jobState: null); if (listOfJobs != null) { Validate(jobCollection[0], listOfJobs.Count); } } JobAction jobAction = this.GetJobAction(createJobParams); JobRecurrence jobRecurrence = this.GetJobRecurrence(createJobParams.JobRecurrence); var properties = new JobProperties() { Action = jobAction, Recurrence = jobRecurrence, StartTime = createJobParams.StartTime, State = createJobParams.JobState.GetValueOrDefaultEnum <JobState?>(defaultValue: null) }; var jobDefinition = new JobDefinition(name: createJobParams.JobName) { Properties = properties }; JobDefinition jobDefinitionResult = this.SchedulerManagementClient.Jobs.CreateOrUpdate(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, createJobParams.JobName, jobDefinition); return(Converter.ConvertJobDefinitionToPS(jobDefinitionResult)); }
/// <summary> /// Gets existing job recurrence. /// </summary> /// <param name="updateRecurrenceParams">Recurrence properties specified via PowerShell.</param> /// <param name="recurrence">Existing job recurrence property.</param> /// <returns>JobRecurrence object.</returns> private JobRecurrence GetExistingJobRecurrence(PSJobRecurrenceParams updateRecurrenceParams, JobRecurrence recurrence) { if (updateRecurrenceParams != null) { if (recurrence == null) { return this.GetJobRecurrence(updateRecurrenceParams); } recurrence.Count = updateRecurrenceParams.ExecutionCount ?? recurrence.Count; recurrence.EndTime = updateRecurrenceParams.EndTime ?? recurrence.EndTime; recurrence.Frequency = updateRecurrenceParams.Frequency.GetValueOrDefaultEnum<RecurrenceFrequency?>(defaultValue: recurrence.Frequency); recurrence.Interval = updateRecurrenceParams.Interval ?? recurrence.Interval; } return recurrence; }
// retrieve the windows azure managment certificate from current user public ApprenticeShipSchedular() { var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "CA4716F85EC0962E2B69BB7D626CC16B924E550D", false)[0]; store.Close(); // // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("bd27a79c-de25-4097-a874-3bb35f2b926a", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create cloud service var cloudServiceCreateParameters = new CloudServiceCreateParameters { Description = "sfaarmscheduler", Email = "*****@*****.**", GeoRegion = "West Europe", Label = "sfaarmscheduler" }; var cloudService = cloudServiceMgmCli.CloudServices.Create("sfaarmscheduler", cloudServiceCreateParameters); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings { //Add Credentials for X.509 Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 1 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "sfajobcollection" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create("sfaarmscheduler", "sfajobcollection", jobCollectionCreateParameters); var schedulerClient = new SchedulerClient("sfaarmscheduler", "sfajobcollection", credentials); var jobAction = new JobAction { Type = JobActionType.StorageQueue, QueueMessage = new JobQueueMessage() { Message = "test", QueueName = "vacancysummaryqueueitem", SasToken = "?sv=2017-04-17&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-09-01T21:58:06Z&st=2017-09-01T13:58:06Z&spr=https&sig=r0u1A01ytcN213lsWO47Td7DUaU7lo3aQTPNTCrHRxU%3D", StorageAccountName = "sfabetastorage" } //Request = new JobHttpRequest //{ // Uri = new Uri("http://blog.shaunxu.me"), // Method = "GET" //} }; var jobRecurrence = new JobRecurrence { Frequency = JobRecurrenceFrequency.Hour, Interval = 1 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate("poll_blog", jobCreateOrUpdateParameters); var jobGetHistoryParameters = new JobGetHistoryParameters { Skip = 0, Top = 100 }; var history = schedulerClient.Jobs.GetHistory("poll_blog", jobGetHistoryParameters); foreach (var action in history) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", action.Status, action.Message, action.RetryCount, action.RepeatCount, action.Timestamp); } }
/// <summary> /// Gets existing job recurrence. /// </summary> /// <param name="updateRecurrenceParams">Recurrence properties specified via PowerShell.</param> /// <param name="recurrence">Existing job recurrence property.</param> /// <returns>JobRecurrence object.</returns> private JobRecurrence GetExistingJobRecurrence(PSJobRecurrenceParams updateRecurrenceParams, JobRecurrence recurrence) { if (updateRecurrenceParams != null) { if (recurrence == null) { return(this.GetJobRecurrence(updateRecurrenceParams)); } recurrence.Count = updateRecurrenceParams.ExecutionCount ?? recurrence.Count; recurrence.EndTime = updateRecurrenceParams.EndTime ?? recurrence.EndTime; recurrence.Frequency = updateRecurrenceParams.Frequency.GetValueOrDefaultEnum <RecurrenceFrequency?>(defaultValue: recurrence.Frequency); recurrence.Interval = updateRecurrenceParams.Interval ?? recurrence.Interval; } return(recurrence); }
private JobCreateOrUpdateParameters GetParams(Task model) { JobCreateOrUpdateParameters p = new JobCreateOrUpdateParameters(); string url; if (Request == null) { url = model.Url; } else { string serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; string host = serverName == "localhost" ? defaultHost : serverName; url = string.Format("http://{0}{1}", host, model.Url); } if (Request == null) { p.Action = new JobAction() { Type = JobActionType.Https, Request = new JobHttpRequest() { Method = "GET", Uri = new Uri(url), } }; p.StartTime = model.Start_Date; } else { p.Action = new JobAction() { Type = JobActionType.Http, Request = new JobHttpRequest() { Body = "", Headers = new Dictionary <string, string>() { { "Content-Type", "application/x-www-form-urlencoded" } }, Method = "GET", Uri = new Uri(url), Authentication = new BasicAuthentication() { Username = systemAccountName, Password = systemAccountPass, Type = HttpAuthenticationType.Basic } } }; p.StartTime = model.Start_Date == null ? DateTime.UtcNow : model.Start_Date + model.Start_Time; } JobRecurrence r = new JobRecurrence(); switch (model.Type) { case ScheduleType.DAILY: r.Frequency = JobRecurrenceFrequency.Day; r.Interval = model.Daily_Repeat; break; case ScheduleType.WEEKLY: r.Frequency = JobRecurrenceFrequency.Week; r.Interval = model.Weekly_Repeat; r.Schedule = new JobRecurrenceSchedule() { Days = GetWeeklyDays(model.Weekly_Days), }; break; case ScheduleType.MONTHLY: r.Frequency = JobRecurrenceFrequency.Month; r.Schedule = CreateMonthlySchedule(model); break; case ScheduleType.ONCE: r.Count = 1; break; case ScheduleType.ONIDLE: throw new NotImplementedException("Pro Azure scheduler nelze plánovat OnIdle úlohy"); } if (model.Repeat == true) { JobRecurrenceSchedule s = r.Schedule ?? new JobRecurrenceSchedule(); int minutes = (int)model.Repeat_Minute; int startHour = model.Start_Time == null ? DateTime.Now.Hour : model.Start_Time.Hours; List <int> minuteSchedule = new List <int>(); for (int i = 1; i <= 60; i++) { if ((i % minutes) == 0) { minuteSchedule.Add(i); } } List <int> hourSchedule = new List <int>(); for (int i = 0; i < model.Repeat_Duration; i++) { int hour = startHour + i; hourSchedule.Add(hour > 23 ? hour - 24 : hour); } s.Minutes = minuteSchedule; s.Hours = hourSchedule; } if (model.End_Date != null) { r.EndTime = model.End_Date + model.End_Time; } p.Recurrence = r; return(p); }
// retrieve the windows azure managment certificate from current user public Schedular() { var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "<ThumbPrint>", false)[0]; store.Close(); // // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("8cb918af-59d0-4b24-893c-15661d048f16", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create cloud service var cloudServiceCreateParameters = new CloudServiceCreateParameters() { Description = "schedulerdemo1", Email = "microsoft.com", GeoRegion = "Southeast Asia", Label = "schedulerdemo1" }; var cloudService = cloudServiceMgmCli.CloudServices.Create("schedulerdemo1", cloudServiceCreateParameters); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings() { Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota() { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence() { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 1 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters() { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "jc1" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create("schedulerdemo1", "jc1", jobCollectionCreateParameters); var schedulerClient = new SchedulerClient("schedulerdemo1", "jc1", credentials); var jobAction = new JobAction() { Type = JobActionType.Http, Request = new JobHttpRequest() { Uri = new Uri("http://blog.shaunxu.me"), Method = "GET" } }; var jobRecurrence = new JobRecurrence() { Frequency = JobRecurrenceFrequency.Hour, Interval = 1 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate("poll_blog", jobCreateOrUpdateParameters); var jobGetHistoryParameters = new JobGetHistoryParameters() { Skip = 0, Top = 100 }; var history = schedulerClient.Jobs.GetHistory("poll_blog", jobGetHistoryParameters); foreach (var action in history) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", action.Status, action.Message, action.RetryCount, action.RepeatCount, action.Timestamp); } }
/// <summary> /// Gets job recurrence. /// </summary> /// <param name="jobRecurrenceParams">Job recurrence properties specified via PowerShell.</param> /// <returns>JobRecurrence object.</returns> private JobRecurrence GetJobRecurrence(PSJobRecurrenceParams jobRecurrenceParams) { if (jobRecurrenceParams != null && (jobRecurrenceParams.Interval != null || jobRecurrenceParams.ExecutionCount != null || !string.IsNullOrWhiteSpace(jobRecurrenceParams.Frequency) || jobRecurrenceParams.EndTime != null)) { var jobRecurrence = new JobRecurrence() { Count = jobRecurrenceParams.ExecutionCount ?? default(int?), Interval = jobRecurrenceParams.Interval ?? default(int?), EndTime = jobRecurrenceParams.EndTime ?? default(DateTime?), Frequency = jobRecurrenceParams.Frequency.GetValueOrDefaultEnum<RecurrenceFrequency?>(defaultValue: null) }; return jobRecurrence; } return null; }
private static void CreateSchedulerJob(AzureDetails details) { // retrieve the windows azure managment certificate from current user var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "<THUMBPRINT of CERTIFICATE>", false)[0]; store.Close(); // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("<Your subscription ID>", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings() { Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota() { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence() { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 24 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters() { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "RunBackupJob" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create(details.ResourceGroup, "RunBackupJob", jobCollectionCreateParameters); //generate sas token var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureWebJobsStorage")); //Set the expiry time and permissions for the container. //In this case no start time is specified, so the shared access signature becomes valid immediately. var sasConstraints = new SharedAccessAccountPolicy { SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddYears(1), Permissions = SharedAccessAccountPermissions.Add | SharedAccessAccountPermissions.Create | SharedAccessAccountPermissions.Delete | SharedAccessAccountPermissions.ProcessMessages | SharedAccessAccountPermissions.Read | SharedAccessAccountPermissions.Write }; var token = storageAccount.GetSharedAccessSignature(sasConstraints); // create job var schedulerClient = new SchedulerClient(details.ResourceGroup, "RunBackupJob", credentials); var jobAction = new JobAction() { Type = JobActionType.StorageQueue, QueueMessage = new JobQueueMessage { Message = details.PairName, QueueName = "get-containers", SasToken = sasConstraints.ToString(), StorageAccountName = "queuefunction" } }; var jobRecurrence = new JobRecurrence() { Frequency = JobRecurrenceFrequency.Hour, Interval = 24 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate(details.ResourceGroup, jobCreateOrUpdateParameters); }