示例#1
0
        public async Task <int> NewJobAsync([FromBody] Job job, CancellationToken token)
        {
            this.logger.LogInformation("New clusrun job called. creating job");
            var jobTable = this.utilities.GetJobsTable();

            job.Id = await this.utilities.GetNextId("Jobs", $"{job.Type}", token);

            this.logger.LogInformation("generated new job id {0}", job.Id);

            var partitionName = utilities.GetJobPartitionKey($"{job.Type}", job.Id);
            var rowKey        = utilities.JobEntryKey;

            var result = await jobTable.ExecuteAsync(
                TableOperation.Insert(new JsonTableEntity(partitionName, rowKey, job)),
                null, null, token);

            this.logger.LogInformation("create job result {0}", result.HttpStatusCode);

            HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)result.HttpStatusCode);

            response.EnsureSuccessStatusCode();

            this.logger.LogInformation("Creating job dispatch message");
            var jobDispatchQueue = this.utilities.GetJobDispatchQueue();

            var jobMsg = new JobDispatchMessage()
            {
                Id = job.Id, Type = job.Type
            };
            await jobDispatchQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(jobMsg)), null, null, null, null, token);

            this.logger.LogInformation("Create job dispatch message success.");

            return(job.Id);
        }
示例#2
0
        public async Task <string> GetAsync(int id, CancellationToken token)
        {
            this.logger.LogInformation("GetAsync called. creating job");
            var jobTable = await this.utilities.GetOrCreateJobsTableAsync(token);

            var job = new Job()
            {
                CommandLine  = "cat /opt/hpcnodemanager/nodemanager.json",
                Id           = id,
                Name         = "testjob",
                RequeueCount = 0,
                State        = JobState.Queued,
                TargetNodes  = new string[] { "evanclinuxdev" },
                Type         = JobType.ClusRun,
            };

            var partitionName = utilities.GetJobPartitionKey($"{job.Type}", job.Id);
            var rowKey        = utilities.JobEntryKey;

            var result = await jobTable.ExecuteAsync(
                TableOperation.Insert(new JsonTableEntity(partitionName, rowKey, job)),
                null, null, token);

            this.logger.LogInformation("GetAsync called. create job result {0}", result.HttpStatusCode);

            this.logger.LogInformation("GetAsync called. Creating job dispatch message");
            var jobDispatchQueue = await this.utilities.GetOrCreateJobDispatchQueueAsync(token);

            var jobMsg = new JobDispatchMessage()
            {
                Id = id, Type = JobType.ClusRun
            };
            await jobDispatchQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(jobMsg)), null, null, null, null, token);

            this.logger.LogInformation("GetAsync called. Create job dispatch message success.");

            return("value");
        }