DEV Community

Beaver Bridge
Beaver Bridge

Posted on

Postgres delete cron schedule

select cron.unschedule('my_jobname');
Enter fullscreen mode Exit fullscreen mode

원래는 이렇게 하면 되는데, prisma migration에서 이걸 그냥 호출하면, my_jobname 이 없을 때는 오류가 난다. 그래서 먼저 검사하도록

DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM cron.job WHERE jobname = 'my_jobname') THEN
    select cron.unschedule('my_jobname');
  END IF;
END$$;
Enter fullscreen mode Exit fullscreen mode

이렇게 하면되는데, 이상하게도 select 대신 perform을 쓰라고 한다. 해보니 오류없이 호출은 되는데, perform은 처음 들어보는데...

아무튼 그래서 완성본은 이런 모습이다.

DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM cron.job WHERE jobname = 'my_jobname') THEN
    perform cron.unschedule('my_jobname');
  END IF;
END$$;

-- KST 00:00(UTC 15:00)에 실행
select cron.schedule('my_jobname', '0 15 * * *', 'select my_function();');
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay