Best way to implement a manually triggered task #1090
-
Not sure if this is more of a Nest.js question than Vendure, but here goes. I want to implement a procedure that will sync some data with a remote server and I need it to be manually triggerable, as well as scheduled to execute periodically. What is the best way to implement the manual trigger? For example, can I do the following:
Does this sound sensible, or are there better ways? While here - how do I run a task periodically? Sorry if this is documented already :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can apply the Auth is handled in the exact same way for REST as with GraphQL - either bearer token or cookie depending on your config. You can see the e2e tests that verify this here: vendure/packages/core/e2e/plugin.e2e-spec.ts Lines 116 to 129 in 97edcb9
Take a look at the official NestJS cron package - since Vendure plugins are essentially just NestJS modules, you should be able to use this exactly as it shows in the docs. |
Beta Was this translation helpful? Give feedback.
Yes, you can apply the
Allow
decorator to a Controller method. I just updated the doc block to state this.Auth is handled in the exact same way for REST as with GraphQL - either bearer token or cookie depending on your config. You can see the e2e tests that verify this here:
vendure/packages/core/e2e/plugin.e2e-spec.ts
Lines 116 to 129 in 97edcb9