Skip to content

[IMP] runbot_merge: add callback on patch application#1430

Open
dylankiss wants to merge 1 commit into
17.0from
17.0-imp-merge-commit-callback
Open

[IMP] runbot_merge: add callback on patch application#1430
dylankiss wants to merge 1 commit into
17.0from
17.0-imp-merge-commit-callback

Conversation

@dylankiss

@dylankiss dylankiss commented Jun 11, 2026

Copy link
Copy Markdown

The Weblate sync server uses this to know when to unlock its components.

Related: https://github.com/odoo/internal/pull/4231

@dylankiss dylankiss force-pushed the 17.0-imp-merge-commit-callback branch from 51458a8 to 329e5bb Compare June 12, 2026 12:57
@dylankiss dylankiss marked this pull request as ready for review June 22, 2026 13:54
@dylankiss dylankiss requested review from mart-e and xmo-odoo June 24, 2026 11:48
Comment thread runbot_merge/models/patcher.py Outdated
Comment on lines +375 to +385
data = {
'jsonrpc': '2.0',
'id': None,
'method': 'call',
'params': {
'repository': self.repository.name,
'branch': self.target.name,
'patch': self.id,
'success': success,
},
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessarily complicated, this has no reason to be jsonrpc it should just be an HTTP POST to the specified URL (which is what the help text hints at), and since the callback is per-patch anyway it should just add the success state to the query parameters: the caller can set whatever state they need in the URL they set.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding jsonrpc, I just took the same approach as the /i18n/merge_commit route in Mergebot. I suppose that doesn't require jsonrpc either then?

Anyway, you're right indeed that it can be made simpler by already passing the necessary state in the URL. Adapting it.

@xmo-odoo xmo-odoo Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding jsonrpc, I just took the same approach as the /i18n/merge_commit route in Mergebot. I suppose that doesn't require jsonrpc either then?

Strictly speaking it doesn't but that's an internal communication between odoo services (and very specifically between the translation server and the mergebot) and that's how mat wrote it, whereas this is more of a general purpose extension.

Incidentally something else I thought of yesterday is that SaasAuth is not necessary either, for authentication of the hook / callback the requesting service can set some sort of random one-time code (which can be the entirety of the state on its side). The callback system is not tied to tx, or to contacting internal odoo services.

Comment thread runbot_merge/models/patcher.py Outdated
# TODO: do better
body=e.args[0] if isinstance(e.args[0], Markup) else Markup("<pre>{}</pre>").format(e),
)
patch._fire_callback(success=False)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to move out of line to a cron job.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure: you want me to trigger a cronjob that does this instead (so it doesn't block the flow)?

@xmo-odoo xmo-odoo Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. A cron on a queue which should probably just take the callback URL and something like a JSON payload of additional parameters (that way if the callback queue is reused for other services that works out of the box).

Comment thread runbot_merge/models/patcher.py Outdated
},
}
try:
res = requests.post(self.callback_url, json=data, auth=SaasAuth(), timeout=30)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 seconds timeout is way too long.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably. It's because the other side is also doing a request to Weblate to unlock components. I can probably move that to a cronjob as well. What timeout would you suggest?

@xmo-odoo xmo-odoo Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github webhooks require a response within 10s, that seems pretty reasonable.

@dylankiss dylankiss force-pushed the 17.0-imp-merge-commit-callback branch from 329e5bb to 56942ee Compare June 29, 2026 15:19
@dylankiss dylankiss requested a review from xmo-odoo June 30, 2026 07:55
@dylankiss dylankiss force-pushed the 17.0-imp-merge-commit-callback branch from 56942ee to fb8a20f Compare June 30, 2026 08:00
We introduce a mechanism of calling a callback URL with the status of a
patch when it either succeeded or failed to apply.

The translations sync server uses this to know when to unlock the
relevant components in Weblate.
@dylankiss dylankiss force-pushed the 17.0-imp-merge-commit-callback branch from fb8a20f to eb9c0f0 Compare June 30, 2026 12:00
@dylankiss

Copy link
Copy Markdown
Author

@xmo-odoo I tried to rework the flow as to your suggestions.
I added an additional field to allow retries (e.g. for transient failures) and process them every 6 hours.
Related adaptation of the translations sync server: https://github.com/odoo/internal/pull/4327

@dylankiss

Copy link
Copy Markdown
Author

@xmo-odoo Small reminder. It'd great if you could have another look 🙏

@xmo-odoo xmo-odoo moved this to done in Mergebot Jul 10, 2026
@xmo-odoo xmo-odoo removed the status in Mergebot Jul 10, 2026
@xmo-odoo xmo-odoo moved this to done in Mergebot Jul 10, 2026
@xmo-odoo

xmo-odoo commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

FWIW I reworked it locally to use the mergebot's retryable queue crons instead of being bespoke, I also changed the value from a direct-serialized python boolean to an integer (1 for success, currently 0 for failure but technically codes -- probably negative -- could be sent for more specific failures if that's of use).

I'll close the PR when it's deployed (unless I forget).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: done

Development

Successfully merging this pull request may close these issues.

2 participants