private void InternalStore(string key, WorkState state)
 {
     using (var stream = File.Create(GetWorkItemPath(key)))
     {
         _serializer.WriteObject(stream, state);
     }
 }
        public void Given_()
        {
            var state = TempFolderStateProvider.CreateInTempFolder("When_read_state_never_saved_before_" + Guid.NewGuid().ToString());
            _storagePath = state.StoragePath;
            Directory.CreateDirectory(_storagePath);
            File.WriteAllText(state.GetWorkItemPath("Foo1"), "Something unethical");

            _readState = state.Retrieve("Foo1");
        }
Пример #3
0
        public JobItem(ISchedulerContext context, JobDefinition definition, WorkState presavedState = null)
        {
            _context = context;
            _definition = definition;
            _created = _context.GetCurrentTime();

            if (presavedState != null)
            {
                _lastCompleteTime = presavedState.LastCompleteTime;
            }

            UpdateState();
        }
        public void Store(string key, WorkState state)
        {
            // This code assumes that in most cases, directory exists
            // so no need to check this every time we want to store something
            // but in case folder not here, create one and try second time

            try
            {
                InternalStore(key, state);
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(_storagePath);
                InternalStore(key, state); // Try second time
            }
        }
Пример #5
0
        public void Run()
        {
            if (_status != JobStatus.Scheduled)
            {
                // Do nothing. Work is already started.
                return;
            }
            _status = JobStatus.Running;
            _lastStartTime = _context.GetCurrentTime();
            _definition.Factory().ContinueWith(t =>
            {
                _status = JobStatus.Pending;
                _lastCompleteTime = _context.GetCurrentTime();

                var run = new JobRun
                {
                    Started = _lastStartTime.Value,
                    Completed = _lastCompleteTime.Value
                };

                if (t.Status == TaskStatus.Faulted)
                {
                    var ex = t.Exception.Flatten().GetBaseException();

                    run.Result = JobRunResult.Failure;
                    run.ResultMessage = ex.ToString();

                    // We need to log this out.
                    //_trace.Value.Error("Command " + cmdKey + " failed to execute.\r\n" + ex.Message, new { Exception = ex, Command = cmd });
                }
                else if (t.Status == TaskStatus.RanToCompletion)
                {
                    run.Result = JobRunResult.Success;
                }

                _previousRuns.Add(run);

                var newWorkState = new WorkState(_lastCompleteTime.Value);

                _context.State.Store(_definition.JobKey, newWorkState);
            });
        }
 public void Given_()
 {
     var state = TempFolderStateProvider.CreateInTempFolder("When_read_state_never_saved_before_" + Guid.NewGuid().ToString());
     _storagePath = state.StoragePath;
     _readState = state.Retrieve("Foo1");
 }
Пример #7
0
 public void Store(string key, WorkState state)
 {
     _store[key] = state;
 }
 public void Store(string key, WorkState state)
 {
     _store[key] = state;
 }