Ejemplo n.º 1
0
        public override string CreateExpiredJob(
            Job job,
            IDictionary<string, string> parameters,
            DateTime createdAt,
            TimeSpan expireIn)
        {
            job.ThrowIfNull("job");
            parameters.ThrowIfNull("parameters");

            var invocationData = InvocationData.Serialize(job);

            var ravenJob = new RavenJob
            {
                Id = Guid.NewGuid().ToString(),
                InvocationData = JobHelper.ToJson(invocationData),
                Arguments = invocationData.Arguments,
                CreatedAt = createdAt,
                ExpireAt = createdAt.Add(expireIn)
            };

            using (var repository = new Repository()) {
                repository.Save(ravenJob);

                if (parameters.Count > 0) {
                    foreach (var parameter in parameters) {
                        repository.Save(new JobParameter
                        {
                            JobId = ravenJob.Id,
                            Name = parameter.Key,
                            Value = parameter.Value
                        });
                    }
                }

                return ravenJob.Id.ToString();
            }
        }
Ejemplo n.º 2
0
        public override string CreateExpiredJob(
            Job job,
            IDictionary<string, string> parameters,
            DateTime createdAt,
            TimeSpan expireIn)
        {
            job.ThrowIfNull("job");
            parameters.ThrowIfNull("parameters");

            using (var repository = _storage.Repository.OpenSession()) {
                var invocationData = InvocationData.Serialize(job);

                var guid = Guid.NewGuid().ToString();

                var ravenJob = new RavenJob {
                    Id = Repository.GetId(typeof(RavenJob), guid),
                    InvocationData = invocationData,
                    CreatedAt = createdAt,
                    Parameters = parameters
                };

                repository.Store(ravenJob);
                repository.Advanced.AddExpire(ravenJob, createdAt + expireIn);

                repository.SaveChanges();

                return guid;
            }
        }