Initial working state: CL3.5 complete (Plesk sync + suspend/unsuspend)

This commit is contained in:
2026-03-05 06:47:43 +00:00
commit a36d55eae5
53 changed files with 9925 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
-- CL3.5: background auto-sync lock primitives
create table if not exists public.job_locks (
job_name text primary key,
locked_at timestamptz not null default now(),
locked_by text,
expires_at timestamptz not null
);
create or replace function public.acquire_job_lock(
p_job_name text,
p_locked_by text,
p_ttl_seconds integer default 240
)
returns boolean
language plpgsql
security definer
set search_path = public
as $$
declare
v_acquired boolean := false;
begin
insert into public.job_locks (job_name, locked_by, locked_at, expires_at)
values (
p_job_name,
p_locked_by,
now(),
now() + make_interval(secs => p_ttl_seconds)
)
on conflict (job_name)
do update
set locked_by = excluded.locked_by,
locked_at = excluded.locked_at,
expires_at = excluded.expires_at
where public.job_locks.expires_at < now();
get diagnostics v_acquired = row_count;
return v_acquired;
end;
$$;
create or replace function public.release_job_lock(p_job_name text)
returns void
language sql
security definer
set search_path = public
as $$
delete from public.job_locks where job_name = p_job_name;
$$;