阿波罗(Apollo):从cron作业中调用变异服务器端吗? [英] Apollo: Call a mutation server-side from cron job?
问题描述
我有一个使用Apollo的Meteor应用,正在使用SyncedCron( https://github .com/percolatestudio/meteor-synced-cron )来安排每2小时对数据库进行一次更新操作.
I have a Meteor app that uses Apollo and I am using SyncedCron (https://github.com/percolatestudio/meteor-synced-cron) to schedule an update operation on the database every 2 hours.
每两个小时,从某个外部API获取X数据,并将其存储在数据库的Y集合中.冲洗并重复.
Every two hours, fetch X data from some external API and store in Y collection of the database. Rinse and repeat.
我的问题是这样的:此更新操作应实现为graphQL突变,并在cron作业中称为服务器端(如果这样,您该怎么做?!),还是应按常规实现JS函数,因为它只会在服务器上执行?
My question is this: should this update operation be implemented as a graphQL mutation, and called server-side from within the cron job (if so, how do you do it?!), or should this be implemented as a normal JS function since it will only ever execute on the server?
通过将您的View组件包装在启用了graphql的HOC中,可以从客户端调用我可以在网上找到的所有变异示例.
All the mutation examples I can find online are invoked from the client by wrapping your View component in a graphql-enabled HOC.
也许我只是误解了突变的范围,而这里更大的问题是是否从服务器调用了 CAN 突变,或者它们是否仅在客户端.
Perhaps I am just misunderstanding the scope of mutations, and the larger question here is whether or not mutations CAN be invoked from the server, or if they are client-side only.
希望在此处找到有关突变最佳做法的一些说明.谢谢!
Hoping to find some clarification here on mutation best practices. Thanks!
推荐答案
我认为您在这里只会使用axios(http调用)或流星方法.我认为变异仅适用于浏览器到服务器.
I think you would just use axios (http call) or a meteor method here. I think mutations are just for browser-to-server.
这篇关于阿波罗(Apollo):从cron作业中调用变异服务器端吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!