use UTC in MySQL backend for workflow started timestamp #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Appropriately handle timestamps for the "workflow started" engine storage interfaces in the MySQL storage backend.
We had a few critical issues with this—namely from using a MySQL
TIMESTAMP
column and using a normaltime.Now()
value:TIMESTAMP
columns convert to UTC for storage, but always parse and present the MySQL system/session local timezone. From the manual: "MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval."time.Time{}
(i.e.time.Now()
with the local TZ) value as-is and simply converted it to a string and stored it.To address all that we now explicitly convert the input Go
time.Time{}
to UTC, then use MySQLCONVERT_TZ()
to convert that UTC timestamp to the session TZ (and: yes, just for MySQL to convert it right back to UTC for storage). As well for reading we ask MySQL to convert from the "presented" session TZ back to UTC (again usingCONVERT_TZ()
) so that Go can use UTC when parsing the queried time. This keeps everything in UTC for the date math in Golang. Updated the tests.An alternate solve for this was to add another storage interface method that explicitly do the date math in the storage backend. E.g. something like
IsWorkflowStartedBefore(time.Duration)
. That may still be a good choice for the future.I've been warned against using
TIMESTAMP
columns in general with MySQL. I was a cavalier with that advice. This is the prize.