public RavenDistributedLock(RavenStorage storage, string resource, TimeSpan timeout, RavenStorageOptions options) { storage.ThrowIfNull("storage"); if (string.IsNullOrEmpty(resource)) { throw new ArgumentNullException(nameof(resource)); } if (timeout.TotalSeconds > int.MaxValue) { throw new ArgumentException($"The timeout specified is too large. Please supply a timeout equal to or less than {int.MaxValue} seconds", nameof(timeout)); } options.ThrowIfNull("options"); _storage = storage; _resource = resource; _options = options; if (!AcquiredLocks.Value.ContainsKey(_resource) || AcquiredLocks.Value[_resource] == 0) { Acquire(timeout); AcquiredLocks.Value[_resource] = 1; StartHeartBeat(); } else { AcquiredLocks.Value[_resource]++; } }
public RavenJobQueue([NotNull] RavenStorage storage, RavenStorageOptions options) { storage.ThrowIfNull("storage"); options.ThrowIfNull("options"); _storage = storage; _options = options; }
public RavenConnection(RavenStorage ravenStorage, RavenStorageOptions options) : this(ravenStorage) { options.ThrowIfNull("options"); _storage = ravenStorage; _options = options; }
public RavenJobQueueProvider([NotNull] RavenStorage storage, [NotNull] RavenStorageOptions options) { storage.ThrowIfNull("storage"); options.ThrowIfNull("options"); _jobQueue = new RavenJobQueue(storage, options); _monitoringApi = new RavenJobQueueMonitoringApi(storage); }
public static IGlobalConfiguration <RavenStorage> UseEmbeddedRavenStorage(this IGlobalConfiguration configuration, RavenStorageOptions options) { configuration.ThrowIfNull("configuration"); options.ThrowIfNull("options"); Repository.Embedded = true; var storage = new RavenStorage(options); return(configuration.UseStorage(storage)); }
public static IGlobalConfiguration <RavenStorage> UseRavenStorage(this IGlobalConfiguration configuration, string connectionUrl, string database, RavenStorageOptions options) { configuration.ThrowIfNull("configuration"); connectionUrl.ThrowIfNull("connectionUrl"); database.ThrowIfNull("database"); options.ThrowIfNull("options"); if (!connectionUrl.StartsWith("http")) { throw new ArgumentException("Connection Url must begin with http or https!"); } Repository.ConnectionUrl = connectionUrl; Repository.DefaultDatabase = database; var storage = new RavenStorage(options); return(configuration.UseStorage(storage)); }
public RavenJobQueue([NotNull] RavenStorage storage, RavenStorageOptions options) { storage.ThrowIfNull("storage"); options.ThrowIfNull("options"); _storage = storage; _options = options; _queue = new Dictionary <string, BlockingCollection <JobQueue> >(); using (var session = _storage.Repository.OpenSession()) { // -- Queue listening if (options.QueueNames == null) { throw new ArgumentNullException("options.QueueNames", "You should define a set of QueueNames."); } var config = session.Load <RavenJobQueueConfig>("Config/RavenJobQueue") ?? new RavenJobQueueConfig(); foreach (var queue in options.QueueNames) { Console.WriteLine($"Starting on queue: {queue}"); // Creating queue _queue.Add(queue, new BlockingCollection <JobQueue>()); // Create subscription (if not already exist) if (!config.Subscriptions.ContainsKey(queue)) { config.Subscriptions[queue] = _storage.Repository .Subscriptions() .Create <JobQueue>(new SubscriptionCriteria <JobQueue>() { KeyStartsWith = $"{Repository.GetId(typeof(JobQueue), queue)}/", PropertiesMatch = new Dictionary <Expression <Func <JobQueue, object> >, RavenJToken>() { { x => x.FetchedAt, RavenJToken.FromObject(null) } } }); } // Open subscription var subscription = _storage.Repository.Subscriptions().Open <JobQueue>( config.Subscriptions[queue], new SubscriptionConnectionOptions() { IgnoreSubscribersErrors = false, Strategy = SubscriptionOpeningStrategy.ForceAndKeep }); // Subscribe to it subscription.Subscribe(new RepositoryObserver <JobQueue>(a => { Console.WriteLine(a.Id); _queue[queue].Add(a); })); } session.Store(config); session.SaveChanges(); } }