public async Task <TObject?> GetByIdAsync <TObject>(Guid id) where TObject : IEntity
        {
            var resultBinary = await _cache.GetAsync(id.ToString());

            if (resultBinary != null)
            {
                return(JsonConvert.DeserializeObject <TObject>(Encoding.UTF8.GetString(resultBinary)));
            }

            var result = await _wrappedDao.GetByIdAsync <TObject>(id);

            if (result != null)
            {
                await _cache.SetAsync(id.ToString(), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(result)));
            }

            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> CreateProjectRevisionAsync(Guid projectId)
        {
            var project = await _dao.GetByIdAsync <Project>(projectId);

            if (project == null)
            {
                return(NotFound($"Project {projectId} doesn't exist."));
            }

            // Set the revision id.
            var revisionId = Guid.NewGuid();
            var revision   = new Revision
            {
                Id          = revisionId,
                ProjectId   = projectId,
                CreatedDate = DateTime.UtcNow
            };

            // firstly get the job runner and then the payload template.
            var jobRunner = await _jobsApiService.GetJobRunnerByIdAsync(project.JobRunnerId);

            var payload = jobRunner.PayloadTemplate;

            // then normalize the payload.
            foreach (var payloadTemplateFunc in PayloadTemplateFuncs)
            {
                payload = payloadTemplateFunc(payload, project, revisionId, jobRunner);
            }

            // and then create the job and get the job submission name.
            var dict    = JsonConvert.DeserializeObject <Dictionary <string, object> >(payload);
            var jobName = await _jobsApiService.SubmitJobAsync(jobRunner.ClusterType, dict);

            revision.JobSubmissionName = jobName;

            // save the revision.
            await _dao.AddAsync(revision);

            return(CreatedAtRoute("GetRevisionById", new
            {
                id = revision.Id
            }, revision.Id));
        }