-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1322 End of task: Wrong worker #905
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
Open
maparent
wants to merge
4
commits into
main
Choose a base branch
from
eng-1322-end-of-task-wrong-worker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/database/supabase/migrations/20260321191952_end_sync_task_w_start_time.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| DROP FUNCTION IF EXISTS public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status); | ||
|
|
||
| CREATE OR REPLACE FUNCTION public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status, | ||
| s_started_at timestamptz = NULL | ||
| ) RETURNS void | ||
| SET search_path = '' | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| DECLARE t_id INTEGER; | ||
| DECLARE t_worker varchar; | ||
| DECLARE t_status public.task_status; | ||
| DECLARE t_failure_count SMALLINT; | ||
| DECLARE t_last_task_start TIMESTAMP WITH TIME ZONE; | ||
| DECLARE t_last_success_start TIMESTAMP WITH TIME ZONE; | ||
| DECLARE t_last_task_end TIMESTAMP WITH TIME ZONE; | ||
| BEGIN | ||
| SELECT id, worker, status, failure_count, last_task_start, last_task_end, last_success_start | ||
| INTO STRICT t_id, t_worker, t_status, t_failure_count, t_last_task_start, t_last_task_end, t_last_success_start | ||
| FROM public.sync_info WHERE sync_target = s_target AND sync_function = s_function; | ||
| ASSERT s_status > 'active'; | ||
| IF t_worker != s_worker AND COALESCE(s_started_at, t_last_task_start) < t_last_task_start THEN | ||
| -- we probably took too long. Let the other task have priority. | ||
| RETURN; | ||
| END IF; | ||
| ASSERT t_worker = s_worker, 'Wrong worker'; | ||
| ASSERT s_status >= t_status, 'do not go back in status'; | ||
| IF s_status = 'complete' THEN | ||
| t_last_task_end := now(); | ||
| t_last_success_start := t_last_task_start; | ||
| t_failure_count := 0; | ||
| ELSE | ||
| IF t_status != s_status THEN | ||
| t_failure_count := t_failure_count + 1; | ||
| END IF; | ||
| END IF; | ||
|
|
||
| UPDATE public.sync_info | ||
| SET status = s_status, | ||
| task_times_out_at=null, | ||
| last_task_end=t_last_task_end, | ||
| last_success_start=t_last_success_start, | ||
| failure_count=t_failure_count | ||
| WHERE id=t_id; | ||
| END; | ||
| $$; | ||
|
|
||
| ALTER FUNCTION public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status, | ||
| s_started_at timestamptz | ||
| ) OWNER TO "postgres"; | ||
|
|
||
| GRANT ALL ON FUNCTION public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status, | ||
| s_started_at timestamptz | ||
| ) TO "anon"; | ||
| GRANT ALL ON FUNCTION public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status, | ||
| s_started_at timestamptz | ||
| ) TO "authenticated"; | ||
| GRANT ALL ON FUNCTION public.end_sync_task( | ||
| s_target bigint, | ||
| s_function character varying, | ||
| s_worker character varying, | ||
| s_status public.task_status, | ||
| s_started_at timestamptz | ||
| ) TO "service_role"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.