public async Task <CreateContestResponse> CreateAsync(CreateContestRequest contest) { var exists = await _contestRepository.FindByTopicAsync(contest.Topic); if (exists != null) { throw new Exception("A contest with the same Topic already exists."); } var result = await _contestRepository.CreateAsync(ContestMapper.MapCreateContestRequestToContestStorage(contest)); if (contest.Current) { await _contestRepository.SetCurrentAsync(result); // Schedule contest closing job var job = new SimpleJob(async scheduledTime => { await UpdateAsync(result, new UpdateContestRequest { Closed = true }); }); _singularity.ScheduleJob(new RunOnceSchedule(TimeSpan.FromMinutes(1)), job, false); } return(new CreateContestResponse { Id = result }); }