-
Notifications
You must be signed in to change notification settings - Fork 14
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
Treat warehouse schedules as in the opscenter-configured timezone. #397
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import streamlit as st | ||
import sthelp | ||
import warehouse_schedule | ||
from modules import add_custom_modules | ||
|
||
|
||
sthelp.chrome("Warehouse Schedule") | ||
|
||
# Load custom OpsCenter python modules | ||
if not add_custom_modules(): | ||
st.warning("Unable to load OpsCenter modules.") | ||
|
||
import warehouse_schedule # noqa E402 | ||
|
||
warehouse_schedule.display() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,23 +10,36 @@ CREATE OR REPLACE PROCEDURE INTERNAL.UPDATE_WAREHOUSE_SCHEDULES(last_run timesta | |
DECLARE | ||
task_outcome variant default (select object_construct()); | ||
BEGIN | ||
-- Get the configured timezone or default to 'America/Los_Angeles' | ||
let tz text; | ||
call internal.get_config('default_timezone') into :tz; | ||
if (tz is null) then | ||
tz := 'America/Los_Angeles'; | ||
end if; | ||
task_outcome := (select object_insert(:task_outcome, 'opscenter timezone', :tz)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure why we have two lines here. as in they are basically the same info right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, one is recording what the configured timezone for OpsCenter is and the other is recording what the default timezone is for the user's Snowflake account. I thought knowing this might be helpful in debugging issues in the future. |
||
task_outcome := (select object_insert(:task_outcome, 'account timezone', internal.get_current_timezone())); | ||
|
||
-- The task calls this procedure with NULL and lets the procedure figure out the details. | ||
-- The ability to specify timestamps is only to enable testing. | ||
if (this_run is NULL) then | ||
this_run := (select current_timestamp()); | ||
this_run := (select CONVERT_TIMEZONE(internal.get_current_timezone(), :tz, current_timestamp())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the behaviour of this when we pass in an LTZ timezone instead of an NTZ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the 3-arg CONVERT_TIMEZONE function, I don't believe there is any difference if you pass an LTZ or an NTZ (because the timestamp is assumed to be in the timezone specified by the first argument). I think changing this procedure to accept an NTZ instead of an LTZ is the way we solve the goofiness of the timestamps shifting when given to a procedure. I had been messing around with this over the weekend which works as I expect:
|
||
else | ||
this_run := (select CONVERT_TIMEZONE(internal.get_current_timezone(), :tz, :this_run)); | ||
end if; | ||
task_outcome := (select object_insert(:task_outcome, 'this_run', :this_run)); | ||
|
||
if (last_run is NULL) then | ||
last_run := (select run from internal.task_warehouse_schedule order by run desc limit 1); | ||
last_run := (select CONVERT_TIMEZONE(internal.get_current_timezone(), :tz, run) from internal.task_warehouse_schedule order by run desc limit 1); | ||
-- If we don't have any rows in internal.task_warehouse_schedule, rewind far enough that we will just pick | ||
-- the current WH schedule and not think it has already been run. | ||
if (last_run is NULL) then | ||
last_run := (select timestampadd('days', -1, current_timestamp)); | ||
last_run := (select CONVERT_TIMEZONE(internal.get_current_timezone(), :tz, timestampadd('days', -1, current_timestamp))); | ||
end if; | ||
else | ||
last_run := (select CONVERT_TIMEZONE(internal.get_current_timezone(), :tz, :last_run)); | ||
end if; | ||
|
||
-- TODO handle looking back over a weekend boundary (from python) | ||
-- TODO handle the timestamp from config (from python) | ||
-- TODO the WEEK_START session parameter can alter what DAYOFWEEK returns. | ||
let is_weekday boolean := (select DAYOFWEEK(:this_run) not in (0, 6)); | ||
|
||
|
@@ -94,3 +107,12 @@ EXCEPTION | |
INSERT INTO internal.task_warehouse_schedule SELECT :this_run, FALSE, :task_outcome; | ||
RAISE; | ||
END; | ||
|
||
-- owners rights procedures can't get the timezone from the session parameters. | ||
CREATE OR REPLACE FUNCTION INTERNAL.GET_CURRENT_TIMEZONE() | ||
RETURNS STRING | ||
LANGUAGE JAVASCRIPT | ||
AS | ||
$$ | ||
return Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this return? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns a timezone identifier like "America/New_York" (or similar). |
||
$$; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't know the account timezone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here we can probably figured it out from Snowflake. I hadn't thought about checking the snowflake default.