How to check number of jobs remaining in job collection of Azure scheculer

157 Views Asked by At

I have implemented Azure scheduler by following below blog

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

Now I am able to create/update/delete jobs in the scheduler but how can I check whether the jobcollection is full? Basically I want to create another collection whenever my current jobcollection is full.

Sharing my code snippet

    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

There are 1 best solutions below

2
On

After looking at the Scheduler API, it seems that there is no straightforward approach to get the length of a Job Collection.

Probably you can attempt to create a Job and if there is a quota error, then you can create a new Job Collection and add that job.