如何检查Azure scheculer的作业集合中剩余的作业数

时间:2016-12-26 06:38:03

标签: azure azure-scheduler

我已按照以下博客

实施了Azure计划程序

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

现在我可以在调度程序中创建/更新/删除作业,但是如何检查jobcollection是否已满?基本上我想在我当前的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);
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

在查看Scheduler API之后,似乎没有直接的方法来获取作业集的长度。

您可以尝试创建作业,如果存在配额错误,则可以创建新的作业集并添加该作业。