0

我通过以下博客实现了 Azure 调度程序

http://fabriccontroller.net/a-complete-overview-to-get-started-with-the-windows-azure-scheduler/

现在我可以在调度程序中创建/更新/删除作业,但是如何检查作业集合是否已满?基本上,只要我当前的 jobcollection 已满,我就想创建另一个集合。

分享我的代码片段

    public class AzureSchedulerStorage : ISchedulerStorage
    {
        private CertificateCloudCredentials credentials;
        //private CloudServiceManagementClient cloudServiceClient;
        private string cloudServiceName;
       // private IHalseyLogger logger;

        public AzureSchedulerStorage(string cloudServiceName, CertificateCloudCredentials credentials)
        {
            this.cloudServiceName = cloudServiceName;
            this.credentials = credentials;
          //  this.logger = logger;
        }

        public SchedulerOperationStatusResponse CreateJobCollection(string jobCollectionName)
        {
            var schedulerServiceClient = new SchedulerManagementClient(credentials);
            var jobCollectionCreateParameters = new JobCollectionCreateParameters()
            {
                Label = jobCollectionName,
                IntrinsicSettings = new JobCollectionIntrinsicSettings()
                {
                    Plan = JobCollectionPlan.Standard,
                    Quota = new JobCollectionQuota()
                    {
                        MaxJobCount = 50,
                        MaxRecurrence = new JobCollectionMaxRecurrence()
                        {
                            Frequency = JobCollectionRecurrenceFrequency.Minute
                        }
                    }
                }
            };

            var result = schedulerServiceClient.JobCollections.Create(this.cloudServiceName, jobCollectionName, jobCollectionCreateParameters);
            return result;

        }

        public JobCollectionGetResponse GetJobCollection(string jobCollectionName)
        {
            var schedulerServiceClient = new SchedulerManagementClient(credentials);
            var result = schedulerServiceClient.JobCollections.Get(this.cloudServiceName, jobCollectionName);
            return result;
        }

        public void CreateOrUpdate(string jobcollectionName, string jobId, DateTime startDate)
        {
            var schedulerClient = new SchedulerClient(this.cloudServiceName, jobcollectionName, this.credentials);
            var job = new JobCreateOrUpdateParameters()
            {
                Action = new JobAction()
                {
                    Type = JobActionType.Https,
                    Request = new JobHttpRequest()
                    {
                        Body = "customer=sandrino&command=sendnewsletter",
                        Headers = new Dictionary<string, string>()
                        {
                            { "Content-Type", "application/x-www-form-urlencoded" },
                            { "x-something", "value123" }
                        },
                        Method = "POST",
                        Uri = new Uri("http://postcatcher.in/catchers/527af9acfe325802000001cb"),

                    }
                },

                StartTime = startDate,
            };

            var result = schedulerClient.Jobs.CreateOrUpdate(jobId, job);
        }
    }
}
4

1 回答 1

-1

在查看了 Scheduler API 之后,似乎没有直接的方法来获取 Job Collection 的长度。

可能您可以尝试创建一个作业,如果存在配额错误,那么您可以创建一个新的作业集合并添加该作业。

于 2016-12-26T07:55:39.853 回答