Example #1
0
        public async Task <string> ExclusiveCreateAsync(string name, IContextParameters @params)
        {
            var userId = _userResolver.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (await _lockService.LockAsync(name) == false)
            {
                await _lockService.UnlockAsync(name);

                //return null;
            }

            var job = await _jobRepository.AddAsync(new Job(name, userId, @params));

            _jobRegistory.AddJob(job);
            _jobRegistory.Enqueue(job.Id);

            return(job.Id);
        }
Example #2
0
        public async Task <string> RegisterAsync(string collectionName, string procedureName, IContextParameters parameters)
        {
            if (collectionName.Contains(':'))
            {
                throw new ArgumentException(nameof(collectionName), "Cannot use delimiter(:)");
            }

            if (procedureName.Contains(':'))
            {
                throw new ArgumentException(nameof(procedureName), "Cannot use delimiter(:)");
            }

            if (GetBuiltinProcedureNames().Contains(procedureName))
            {
                return(await _jobs.ExclusiveCreateAsync($"{BUILTIN}:{collectionName}:{procedureName}", parameters));
            }

            var collection = await _settings.FindCollectionAsync(collectionName);

            var info = collection.Procedures?.Where(procedure => procedure.Name == procedureName).FirstOrDefault();

            if (info != null)
            {
                return(await _jobs.ExclusiveCreateAsync($"{CUSTOM}:{collectionName}:{procedureName}", parameters));
            }

            throw new NotSupportedException($"{procedureName} is not supported.");
        }