Apollo:从 cron 作业调用一个变更服务器端? [英] Apollo: Call a mutation server-side from cron job?

查看:25
本文介绍了Apollo:从 cron 作业调用一个变更服务器端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 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.

也许我只是误解了突变的范围,这里更大的问题是是否可以从服务器调用突变,或者它们是否仅在客户端调用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆