Skip to content
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

Split the procrastinate_finish_job SQL function into two functions #332

Closed
elemoine opened this issue Oct 9, 2020 · 2 comments · Fixed by #336
Closed

Split the procrastinate_finish_job SQL function into two functions #332

elemoine opened this issue Oct 9, 2020 · 2 comments · Fixed by #336
Assignees
Labels
Issue appropriate for: newcomers 🤩 This issue can be safely tackled by people who never worked in this project before Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some SQL 🐘 This features require changing the SQL model

Comments

@elemoine
Copy link
Contributor

elemoine commented Oct 9, 2020

The procrastinate_finish_job SQL function looks like this currently:

https://github.com/peopledoc/procrastinate/blob/f831565b00d67afa7a4291d734c8fe85074a360c/procrastinate/sql/schema.sql#L175-L185

scheduled_at only makes sense for retries.

So @ewjoachim and I suggest that we split this function into two functions:

CREATE FUNCTION procrastinate_finish_job(job_id integer, end_status procrastinate_job_status) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE procrastinate_jobs
    SET status = end_status,
        attempts = attempts + 1
    WHERE id = job_id;
END;
$$;

CREATE FUNCTION procrastinate_retry_job(job_id integer, retry_at timestamp with time zone) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE procrastinate_jobs
    SET status = 'todo',
        attempts = attempts + 1,
        scheduled_at = retry_at
    WHERE id = job_id;
END;
$$;

And call the appropriate function from the worker code.

@elemoine elemoine added Issue appropriate for: newcomers 🤩 This issue can be safely tackled by people who never worked in this project before Issue contains: Some SQL 🐘 This features require changing the SQL model Issue contains: Some Python 🐍 This issue involves writing some Python code Issue type: Refactor labels Oct 9, 2020
@ewjoachim
Copy link
Member

BTW, it would be great if the increment part could be handled by a trigger. That would avoid mistakes and help the data be consistent.

@ewjoachim
Copy link
Member

Note: solving this will lead us to the right direction for solving #307 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue appropriate for: newcomers 🤩 This issue can be safely tackled by people who never worked in this project before Issue contains: Some Python 🐍 This issue involves writing some Python code Issue contains: Some SQL 🐘 This features require changing the SQL model
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants