Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify timestamp storage #674

Merged
merged 19 commits into from
Sep 15, 2020
Merged

Unify timestamp storage #674

merged 19 commits into from
Sep 15, 2020

Conversation

mostlyobvious
Copy link
Member

@mostlyobvious mostlyobvious commented Oct 4, 2019

[#627]

Breaking changes so far:

  • format of serialized message for async jobs (problematic when deploying changes — workers need strategy to handle both formats for a while, also RES client must be able to deserialize both)
  • ROM timestamps changed to local time as Sequel expects, where previously put as UTC interpreted as a local time — mostlī harmless if you acknowledge time skew before certain point in time

Doubts:

  • SerializedRecord#timestamp as a Time object or just an ISO8601 string? The latter better for async jobs, the former suits adapters better and requires less instantiations — do we miss some other kind of SerializedRecord or need a different internal Record?
  • repositories use SerializedRecord#timestamp as a source for persisted timestamp (created_at in schema)

Future extensions on in this PR:

  • exposing link time (created_at in event_store_events_in_streams)
  • bi-temporal modeling, need one (or more) additional timestamp
  • filtering by timestamp

@mostlyobvious mostlyobvious force-pushed the timestamp-like-a-boss branch 4 times, most recently from 537491e to c29af6f Compare October 8, 2019 22:02
mostlyobvious referenced this pull request Oct 18, 2019
Event timestamp in an instance of Time.
Copy link
Contributor

@swistak35 swistak35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I haven't reviewed protobuf part and ROM part

@@ -18,7 +18,7 @@ def append_to_stream(events, stream, expected_version)
event_ids << event.event_id
end
add_to_stream(event_ids, stream, expected_version, true) do
Event.import(records)
Event.import(records, timestamps: false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does a false do here? we definitely want timestamps from an event, not a database/activerecord generated one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/zdennis/activerecord-import#activerecord-timestamps

Should you wish to specify those columns, you may use the option timestamps: false.

However next paragraph might cause this to be obsolete:

However, it is also possible to set just :created_at in specific records. In this case despite using timestamps: true, :created_at will be updated only in records where that field is nil. Same rule applies for record associations when enabling the option recursive: true

@@ -222,8 +222,16 @@ def with_metadata(metadata, &block)
# {http://railseventstore.org/docs/subscribe/#async-handlers Read more}
#
# @return [Event, Proto] deserialized event
def deserialize(event_type:, event_id:, data:, metadata:)
mapper.serialized_record_to_event(SerializedRecord.new(event_type: event_type, event_id: event_id, data: data, metadata: metadata))
def deserialize(event_type:, event_id:, data:, metadata:, timestamp:)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test case for timestamp: nil and timestamp still passed as metadata

"metadata" => "---\n:timestamp: 2019-09-30 00:00:00.000000000 Z\n",
"_aj_symbol_keys" => %w[event_id data metadata event_type],
"metadata" => "--- {}\n",
"timestamp" => {"_aj_serialized"=>"ActiveJob::Serializers::TimeSerializer", "value"=>"2019-09-30T00:00:00Z"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AJ specific, would prefer something more generic even if just for AJ

@mostlyobvious mostlyobvious force-pushed the timestamp-like-a-boss branch 10 times, most recently from 48c0cfe to 29c8ed1 Compare September 12, 2020 21:22
@mostlyobvious
Copy link
Member Author

Probably needs database migrations for mysql to upgrade timestamp resolution.

@@ -8,7 +8,8 @@ def dump(item)
event_id: item.event_id,
metadata: ActiveSupport::HashWithIndifferentAccess.new(item.metadata).deep_symbolize_keys,
data: ActiveSupport::HashWithIndifferentAccess.new(item.data).deep_symbolize_keys,
event_type: item.event_type
event_type: item.event_type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should exclude this change in contrib project. It depends on already released RubyEventStore gem version and this will break the tests as timestamp changes has not yet been released. Also IMO we should avoid mixing contrib projects changes into PR with main gems code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants