//protected void InitializeConfiguration(IConfig config) //{ // var hostKey = config[BlobContainerLocalConfig.ContainerHost]; // _containerName = config[BlobContainerLocalConfig.ContainerName]; // _host = hostKey; // _container = _containerName; // _access = (EntityAccess)Enum.Parse(typeof(EntityAccess), // config.Get(BlobContainerLocalConfig.OptionalAccess, // EntityAccess.Private.ToString())); //} protected void InternalSaveObject <TData>(string objId, TData obj) { try { if (mutex.Wait(TimeSpan.FromSeconds(DefaultTime))) { var data = JsonConvert.SerializeObject(obj); if (_persistentDictionary.ContainsKey(objId)) { _persistentDictionary[objId] = data; } else { _persistentDictionary.Add(objId, data); } _persistentDictionary.Flush(); mutex.Release(); } } catch (Exception ex) { throw new BlobAccessException(ex); } }
public override int ProcessItems() { if (_paused) { return(0); } _jobsMutex = Catalog.Preconfigure() .Add(DistributedMutexLocalConfig.Name, ScheduledItem.MutexName) .ConfiguredResolve <IDistributedMutex>(); try { if (_jobsMutex.Wait(TimeSpan.FromMinutes(4))) { var dueCount = 0; using (_jobsMutex) { if (_jobsMutex.Open()) { _dblog.InfoFormat("Worker {0} processing scheduled jobs", _hostEnv.GetCurrentHostIdentifier( HostEnvironmentConstants.DefaultHostScope)); var due = _jobScheduler.GetDue(); dueCount = due.Count(); _log.InfoFormat("Processing {0} due jobs", due.Count()); foreach (var item in due) { _token.ThrowIfCancellationRequested(); _dblog.InfoFormat("Job due, starting {1} {2} : {0}", item.Message, item.Type, item.Route); _jobScheduler.Reschedule(item); var message = JsonConvert.DeserializeObject(item.Message, item.Type); _sender.Send(message, item.Route); } } } return(dueCount); } } catch (Exception ex) { _log.ErrorFormat(string.Format("An Exception was Caught in {0} ERROR: {1}", this.GetType().Name, ex.Message)); } return(0); }
private const int DefaultTime = 30;//seconds public EsentBlobContainer() { var cf = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _host = cf[BlobContainerLocalConfig.ContainerHost]; _container = cf[BlobContainerLocalConfig.ContainerName]; _path = new Uri(string.Format("file:///{0}", Path.Combine(_host, _container))).LocalPath; mutex = Catalog.Preconfigure().Add(DistributedMutexLocalConfig.Name, "ApplicationDeployments").ConfiguredResolve <IDistributedMutex>(); if (mutex.Wait(TimeSpan.FromSeconds(DefaultTime))) { _persistentDictionary = new Microsoft.Isam.Esent.Collections.Generic.PersistentDictionary <string, string>(_path); mutex.Release(); } else { throw new TimeoutException("ApplicationDeployments Mutex Timeout"); } }
public WorkflowAgent(WorkflowHost host, string newId, CancellationToken ct, string initialData, string templateData, string workflowDataRepositoryKey, string workflowMessagingKey, string workflowWorkspaceKey) { Id = newId; _ct = ct; _workflowDataRepositoryKey = workflowDataRepositoryKey; _workflowWorkspaceKey = workflowWorkspaceKey; _instanceData = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowInstanceInfo>() .ConfiguredResolve <IDataRepositoryService <WorkflowInstanceInfo, WorkflowInstanceInfo, DataEnvelope <WorkflowInstanceInfo, NoMetadata>, NoMetadata, DatumEnvelope <WorkflowInstanceInfo, NoMetadata>, NoMetadata> > (_workflowDataRepositoryKey); _triggers = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowTrigger>() .ConfiguredResolve <IDataRepositoryService <WorkflowTrigger, WorkflowTrigger, DataEnvelope <WorkflowTrigger, NoMetadata>, NoMetadata, DatumEnvelope <WorkflowTrigger, NoMetadata>, NoMetadata> > (_workflowDataRepositoryKey); Initialize(host, templateData); if (!string.IsNullOrEmpty(initialData)) { var initialDataSet = JsonConvert.DeserializeObject <Dictionary <string, string> >(initialData); try { foreach (var id in _inputDefinitions.EmptyIfNull().Where(def => !def.Optional)) { if (!initialDataSet.ContainsKey(id.WorkspaceKey)) { throw new InvalidWorkflowInputsException(string.Format("workspace inputs require {0}, not found", id.WorkspaceKey)); } } if (!_wfLock.Wait(TimeSpan.FromSeconds(300.0))) { throw new SynchronizationLockException(string.Format("Timeout waiting for workspace data to {0}", Id)); } Workspace.Batch( wsd => initialDataSet.ForEach(datum => wsd.Put(datum.Key, datum.Value)) ); } catch (Exception ex) { var es = string.Format("Exception initializing workspace inputs, {0}", ex.Message); _log.Error(es); ex.TraceInformation(); var on = Catalog.Factory.Resolve <IApplicationAlert>(); on.RaiseAlert(ApplicationAlertKind.System, es); throw; } finally { _wfLock.Release(); } } }