/// <inheritdoc />
 public DateTimeOffset Handle(GetJobLastKnownEventQuery query)
 {
     using (var connection = _dbConnectionFactory.Create())
     {
         connection.Open();
         using (var command = connection.CreateCommand())
         {
             _prepareQuery.Handle(query, command, CommandStringTypes.GetJobLastKnownEvent);
             using (var reader = command.ExecuteReader())
             {
                 return(reader.Read() ? _readColumn.ReadAsDateTimeOffset(CommandStringTypes.GetJobLastKnownEvent, 0, reader) : default(DateTimeOffset));
             }
         }
     }
 }
        private QueueStatuses RunQuery(DoesJobExistQuery <TConnection, TTransaction> query, IDbConnection connection, IDbTransaction transaction)
        {
            var returnStatus = QueueStatuses.NotQueued;

            using (var command = connection.CreateCommand())
            {
                command.Transaction = transaction;
                _prepareQuery.Handle(query, command, CommandStringTypes.DoesJobExist);
                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        returnStatus =
                            (QueueStatuses)_readColumn.ReadAsInt32(CommandStringTypes.DoesJobExist, 0, reader);
                    }
                }

                if (returnStatus == QueueStatuses.NotQueued &&
                    _tableExists.Handle(new GetTableExistsQuery(_connectionInformation.ConnectionString,
                                                                _tableNameHelper.JobTableName)))
                {
                    command.CommandText =
                        _commandCache.GetCommand(CommandStringTypes.GetJobLastScheduleTime);
                    command.Transaction = transaction;
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(returnStatus);
                        }
                        var scheduleTime =
                            _readColumn.ReadAsDateTimeOffset(CommandStringTypes.GetJobLastScheduleTime, 0, reader);
                        if (scheduleTime == query.ScheduledTime)
                        {
                            return(QueueStatuses.Processed);
                        }
                    }
                }
            }
            return(returnStatus);
        }