简体   繁体   English

Java 中 12 因素的管理流程

[英]Admin Process for 12-factor in Java

The 12-Factor blog suggests an App should 'Run admin/management tasks as one-off processes'. 12-Factor 博客建议应用程序应“将管理/管理任务作为一次性流程运行”。

What does that mean in the context of a Java/ Spring-boot application?这在 Java/Spring-boot 应用程序的上下文中意味着什么? Can I get an example.我能举个例子吗。

https://12factor.net/admin-processes https://12factor.net/admin-processes

The site does not suggest this.该网站不建议这样做。 It says that developers may want to do this , and that if they do so, they should apply the same standards as other code :它说开发人员可能想要这样做如果他们这样做,他们应该应用与其他代码相同的标准

One-off admin processes should be run in an identical environment as the regular long-running processes of the app.一次性管理进程应在与应用程序的常规长期运行进程相同的环境中运行。 They run against a release, using the same codebase and config as any process run against that release.它们针对某个版本运行,使用与针对该版本运行的任何进程相同的代码库和配置。 Admin code must ship with application code to avoid synchronization issues.管理代码必须与应用程序代码一起发布以避免同步问题。

As an example from my application: Users may send invitations , to which the recipient must respond within 7 days or the invitation expires.作为我的应用程序的示例:用户可以发送邀请,收件人必须在 7 天内回复,否则邀请将过期。 This is implemented by having a timestamp on the invitation and executing a database query equivalent to DELETE FROM Invitations WHERE expiration < NOW() .这是通过在邀请上设置时间戳并执行相当于DELETE FROM Invitations WHERE expiration < NOW()的数据库查询来实现的。

Now, we could have someone log in to the database and execute this query periodically.现在,我们可以让某人登录到数据库并定期执行此查询。 Instead, however, this "cleanup" operation is built into the application at a URL like /internal/admin/cleanInvitations , and that endpoint is executed by an external cron job.然而,此“清理”操作内置于位于 URL 的应用程序中,例如/internal/admin/cleanInvitations ,并且该端点由外部 cron 作业执行。 The scheduling is outside the main application, but all database configuration, connectivity, and logic are contained within it alongside our main business logic.调度在主应用程序之外,但所有数据库配置、连接和逻辑都与我们的主要业务逻辑一起包含在其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM