我可以从 postgres 触发器执行 cURL 调用吗

发布于 2024-10-04 19:54:48 字数 273 浏览 0 评论 0原文

我必须对处于特定状态的数据库字段创建流程调用。我听说你可以使用 db 触发器执行 cURL 调用,但 Google 并没有足够友善地返回我可以使用的任何内容。

所以我想我的问题是三个部分:

  1. 这可以做到吗?
  2. 参考?
  3. 替代解决方案?

工作流程:

数据库字段随状态更新,需要启动在我的工作流程中运行下一步的脚本/请求/流程(这是一个 PHP 脚本),它将拉取数据库中的记录并处理另一个步骤,然后更新db 与结果。

I have to create a process call on a db field(s) being a certain status. I have heard you can execute a cURL call with a db trigger but Google is not being kind enough to return anything I can use.

So I guess my question is three parts:

  1. Can this be done?
  2. Reference?
  3. Alternative Solution?

Workflow:

db field is updated with status, need to kick off script/request/process that run the next step in my work flow (This is a PHP script) that will pull the recorded in the db and process another step, then update the db with the results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木有鱼丸 2024-10-11 19:54:48

您不应该为此使用触发器,因为触发器会阻止事务,因此它会使您的数据库非常慢。此外,您还需要在 Postgres 中安装不安全的语言 - pl/sh、pl/perl、pl/python 或其他语言。

对于这个问题有两个更好的解决方案:

  • 有一个连接到数据库的进程和监听生成的 NOTIFY 事件通过您的触发器 - 这将立即起作用;

  • 使用例如 cron 脚本定期检查新数据 - 这会产生延迟。

You shouldn't use triggers for that, as a trigger blocks transactions so it will make your database very slow. Also you'd need to install unsafe language to Postgres — pl/sh, pl/perl, pl/python or other.

There are 2 better solutions for this problem:

  • have a process which connects to database and LISTENs for NOTIFY events generated by your trigger — this will work instantly;

  • periodically check for new data using, for example, a cron script - this would work with a delay.

无法言说的痛 2024-10-11 19:54:48

如果你可以调用shell脚本,
http://plsh.projects.postgresql.org/
你可以调用curl。

但我对这种方法有一种令人毛骨悚然的感觉......

  • 如果远程服务器离线,数据不一致?

替代方案:

  • 我不会将业务逻辑放入触发器中,仅将自定义约束或反规范化放入其中。

  • 使用中间层或存储过程执行您需要执行的操作。

问候,
//t

If you can call a shell script,
http://plsh.projects.postgresql.org/
you can call a curl.

But I get a creepy feeling about the approach...

  • If the remote server goes offline, data inconsistency??

Alternative:

  • I wouldn't put business logic in triggers, only customized constraints or denormalisation.

  • Do what you need to do with either middle-tier, or stored procedures.

Regards,
//t

っ〆星空下的拥抱 2024-10-11 19:54:48

我认为你正在寻找的是 postgres 中的一个触发器,它将运行必要的脚本。触发器在文档中进行了解释,添加新触发器的语法是此处解释。您正在寻找的触发器类型似乎是 AFTER UPDATE 触发器。据我所知,您运行的脚本必须检查该字段是否处于所需状态,因为 postgres 将始终运行触发器。

I think what you're looking for is a trigger in postgres that will run the necessery script. Triggers are explained in the documentation, the syntax for adding a new trigger is explained here. The trigger type you're looking for appears to be an AFTER UPDATE trigger. As far as I know, the script you run will have to check if the field is of the required status, as postgres will always run the trigger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文