Does every published Rails Event Store event have a timestamp? - ruby-on-rails

Does every Rails Event Store event that's been published automatically get assigned a timestamp? I'm trying to build functionality that relies upon a timestamp automatically being present for events deserialized from the event_store within a job, but I don't know that I can rely on that. I'm hoping that one does not need to manually add a timestamp to the event's metadata in order for a timestamp to be present, since it doesn't appear that that's been done anywhere in the code base I'm working on. I'm aware that the docs indicate that the return value of the RubyEventStore::Event#timestamp method can be nil, but I'm hoping that it won't be nil for published events.

Unless you provide your own timestamp (the :timestamp key in metadata) each stored event will have metadata enriched with current time - see https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/client.rb#L311
It can be nil. But only if your clock provided to RailsEventStore client will return nil.
In upcoming Rails Event Store 2.0 release we will also add the validity time (valid_at attribute in metadata) that will allow to implement BI Temporal event sourcing. Stay tuned.

Related

Outlook calendar event id's are unique across tenant?

Am working with storing multiple tenants calendar events data on a single database. If calendar event-id are unique across tenant, I will use this as primary key to store unique events
Fetching data using Graph API events delta query
Thanks in advance..
My suggestion is that you'd better to use other key to be the primary key such as timestamp like 20210122125959333.
Upon your question, I googled for help, and based on this document, it seems that there will be 2 same event id. But based on this one, it seems that event ids are unique.
So I did some tests. I used creating event api to create calendar events, and I used the same parameters to test whether it will appear same id, and here is my conclusion.
First, if I used the sample parameter(my url is: https://graph.microsoft.com/v1.0/me/calendar/events) in this document, after executing the api for several times, it will always return similar reponse but the event ids are the same(you can see details in screenshoot), but when I querying events by api, I can only get one event.
Then I set "transactionId" as "" and change the subject of event in parameter json(because when I just change the value of subject, it will return an error describes that I can't use the same transactionId), after executing serveral times, I can get different event ids even using the same parameter.
So my suggestion is you shouldn't use event id as primary key unless your system doesn't care the operation metioned above which returning the same id and prepare to set up a good validation to avoid appearing same event id.

iOS: update a field in model any time managed object model gets modified

I have a "last updated" field on my model. Any time a managed object model gets changed, I'd like that field to get updated. Is there any way I can have this happen automatically? Or do I need to just update that field manually when I make the other modifications?
"Is there any way I can have this happen automatically?"
No. Core Data is not a database, it's an API for abstract object graph management. It has no concept of uniqueness, auto-incrementing values, etc.
"Or do I need to just update that field manually when I make the other modifications?"
Correct, for example having a lastModified property that your application sets with each change.
You could KVO all keys in your entity but maybe this is not necessary. I would suggest you only update the lastUpdated property when you actually save the object because before that you could still just throw away the changes (either on purpose or e.g. because the app terminates).
Therefore, you can simply override willSave. This is specifically designed for this kind of situation (it mentions a "last-modified" attribute), but note the caveats mentioned in the documentation
If you want to update a persistent property value, you should typically test for equality of any new value with the existing value before making a change. If you change property values using standard accessor methods, Core Data will observe the resultant change notification and so invoke willSave again before saving the object’s managed object context. If you continue to modify a value in willSave, willSave will continue to be called until your program crashes.
For example, if you set a last-modified timestamp, you should check whether either you previously set it in the same save operation, or that the existing timestamp is not less than a small delta from the current time. Typically it’s better to calculate the timestamp once for all the objects being saved (for example, in response to an NSManagedObjectContextWillSaveNotification).

How to register events posted from Firebird with parameters in Delphi

I have an event posted from firebird database in a trigger after a new record is inserted like this: post_event 'SPOOL' + new.username;
I want to register this event with SIBfibEventAlerter (FIBPlus) in a Delphi application and run a procedure. Problem is that event name depends on user name added the record.
You could read the usernames from the user table (if new.username is actually a field and not some FB system value) and create the eventalerters components dynamically, one per user name.
Since events don't really support parameters, one way would be to add extra fields to table, which contain auto incremental id (or timestamp) and the data you need as a parameter.

Can I filter OData resources by last updated date?

Is it possible to query an OData collection filtering by the updated metadata field? The case for that would be to get a list of updates since the last check.
I've tried http://odata.netflix.com/v1/Catalog/People?$filter=updated%20eq%202011-05-15T21:45:31Z, but it gives me "No property 'updated' exists in type 'Netflix.Catalog.Person' at position 0". Is there another way I can do this or reference the updated property in a filter statement?
The updated element in the ATOM feed/entry representation may or may not contain actual data. Some services actually do store the real updated timestamp there, but some don't. Since the element is required to be present in all entries by the ATOM format, services which don't have the data to use there usually put some arbitrary timestamp as the value (by default WCF Data Services uses DateTime.Now for the updated field, which is what netflix service does as well).
The $filter can only reference real properties on a given entity. So if the service does have a property which contains the data backing the updated element you would need to find out the name of such property (in the $metadata for example) and then use that. If the service does not have a property like that (for example the netflix service doesn't), then there's no way to filter based on last updated timestamp, as there's no such thing in the underlying data store (the updated element is effectively a fake).
Also note that if you ask for JSON payload the updated element doesn't exist there and so only the real properties are present. Any query operators in the URL work only on the real properties.

ASP.NET MVC Ajax

I would like to have a page that checks for updates to a database table and refreshes the grid using an Ajax call and when a new row is inserted into the table pop up a message window.
This database table gets updated with new rows every 15 minutes or so and the message window lets the user know that a new record has been added or possibly more than one record.
I'm wanting to do this in ASP.NET MVC with Ajax but have no idea how to go about setting up the javascript to check for updates on a timer or if there's a flag that the XHR uses to indicate a change in state.
You should try PokeIn library. It helps you to notify connected clients based on server side events. Here is a basic scenario;
Single static timer runs on the server side and checks any changes on DB. If an update is available sends it to connected clients / associated groups etc.
Samples are available from
This could be a possible way to do it:
Store the time when the data is aquired in a global variable in javascript.
Every x minutes, you do a javascript call to an action method with the timestamp as parameter. This can be done for example using the jQuery Timer as suggested by Rony.
The action method checks the database to see if anything has changed or not, and returns a simple boolean 1/0.
If, and only if, the data has changed, you get the new data from another action method and notify the user that new data has been retrieved.
you can use jQuery timers to check the state of the database using ajax and then modify the values in the table accordinly

Resources