Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog 9.x

- `Sequent.configuration.time_precision` uses the current value of
`ActiveSupport::JSON::Encoding.time_precision` when it is not set,
instead of the value ActiveSupport had when Sequent was loaded.
`Sequent::Configuration::DEFAULT_TIME_PRECISION` is removed.

- A record class that includes `Sequent::Core::ProjectionRecord` can
only be written by projectors, unless writing is allowed using
`Sequent::Core::ProjectionWrites`. The `have_no_write_callbacks`
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ For the latest configuration possibilities please check the `Sequent::Configurat
| snapshot_record_class | The [class](event_store.html) mapped to the `snapshot_records` table | `Sequent::Core::SnapshotRecord` |
| stream_record_class | The [class](event_store.html) mapped to the `stream_records` table | `Sequent::Core::StreamRecord` |
| strict_check_attributes_on_apply_events | Whether or not sequent should fail on calling `apply` with invalid attributes. | `false`. Will be enabled by default in the next major release. |
| time_precision | Sets the precision of encoded time values. Defaults to 3 (equivalent to millisecond precision) | `ActiveSupport::JSON::Encoding.time_precision` |
| time_precision | Sets the precision of encoded time values. When not set, the current value of `ActiveSupport::JSON::Encoding.time_precision` is used | `ActiveSupport::JSON::Encoding.time_precision` |
| transaction_provider | The transaction provider used by the [CommandService](command-service.html) | `Sequent::Core::Transactions::ActiveRecordTransactionProvider.new` |
| uuid_generator | The UUID Generator used. Mainly useful for testing | `Sequent::Core::RandomUuidGenerator` |
| versions_table_name | The name of the table in which Sequent checks which [migration version](migrations.html) is currently active | `'sequent_versions'` |
Expand Down
11 changes: 6 additions & 5 deletions lib/sequent/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class Configuration
fail Sequent::Core::AggregateInvariantViolationError.new(aggregate, exception, phase), cause: exception
end

DEFAULT_TIME_PRECISION = ActiveSupport::JSON::Encoding.time_precision

DEFAULT_AGGREGATE_SNAPSHOT_VERSIONS = proc do |clazz|
Sequent::Core::AggregateRoots.snapshot_version_by_type(clazz)
end
Expand Down Expand Up @@ -77,14 +75,15 @@ class Configuration
:replay_group_target_size,
:event_store_schema_name,
:strict_check_attributes_on_apply_events,
:time_precision,
:enable_autoregistration,
:aggregate_snapshot_versions,
:aggregate_invariant_violation_handler,
:projectors_replayer_after_prepare_hook,
:projectors_replayer_after_activate_hook,
:projectors_replayer_total_lock_timeout

attr_writer :time_precision

attr_reader :migrations_class,
:versions_table_name

Expand Down Expand Up @@ -139,15 +138,17 @@ def initialize
self.logger = Logger.new(STDOUT).tap { |l| l.level = Logger::INFO }
self.error_locale_resolver = DEFAULT_ERROR_LOCALE_RESOLVER

self.time_precision = DEFAULT_TIME_PRECISION

self.enable_autoregistration = false
self.aggregate_snapshot_versions = DEFAULT_AGGREGATE_SNAPSHOT_VERSIONS
self.aggregate_invariant_violation_handler = DEFAULT_AGGREGATE_INVARIANT_VIOLATION_HANDLER

self.projectors_replayer_total_lock_timeout = 10.seconds
end

def time_precision
@time_precision || ActiveSupport::JSON::Encoding.time_precision
end

def versions_table_name=(table_name)
fail ArgumentError, 'table_name can not be nil' unless table_name

Expand Down
22 changes: 22 additions & 0 deletions spec/lib/sequent/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
describe Sequent::Configuration do
let(:instance) { described_class.instance }

describe '#time_precision' do
around do |example|
precision = ActiveSupport::JSON::Encoding.time_precision
example.run
ensure
ActiveSupport::JSON::Encoding.time_precision = precision
end

it 'uses the current time precision of ActiveSupport when not set' do
ActiveSupport::JSON::Encoding.time_precision = 6

expect(instance.time_precision).to eq 6
end

it 'uses the time precision that is set' do
instance.time_precision = 0
ActiveSupport::JSON::Encoding.time_precision = 6

expect(instance.time_precision).to eq 0
end
end

context Sequent::Core::BaseCommandHandler do
class SpecHandler < Sequent::Core::BaseCommandHandler
# rubocop:disable-next Lint/UselessMethodDefinition
Expand Down
Loading