public override void AddJobState(string jobId, IState state)
        {
            using (var repository = new Repository()) {
                var jobState = new State
                {
                    Id = Guid.NewGuid().ToString(),
                    JobId = jobId,
                    Name = state.Name,
                    Reason = state.Reason,
                    CreatedAt = DateTime.UtcNow,
                    Data = JobHelper.ToJson(state.SerializeData())
                };

                repository.Save(jobState);
            }
        }
        public override void SetJobState(string jobId, IState state)
        {
            using (var repository = new Repository()) {
                var jobState = repository.Session.Query<State>().FirstOrDefault(t => t.JobId == jobId);

                if (jobState == null) {
                    jobState = new State
                    {
                        CreatedAt = DateTime.UtcNow,
                        JobId = jobId
                    };
                }

                jobState.Reason = state.Reason;
                jobState.Name = state.Name;
                jobState.Data = JobHelper.ToJson(state.SerializeData());

                repository.Save(jobState);

                var result = repository.Session.Load<RavenJob>(jobId);

                result.StateId = jobState.Id;
                result.StateName = state.Name;
                result.StateData = JobHelper.ToJson(state.SerializeData());
                result.StateReason = state.Reason;

                repository.Save(result);
            }
        }