REST Resource Javascript run on cron or in background


(Nic Hubbard) #1

Is it possible to use a REST Resource Javascript asset and run it as a background job or a cron job? Or does it need to be loaded on the front end in a browser?

If it does have this limitation, are there any other solutions for running server side javascript without having to load a front end page?


(Marcus Fong) #2

Both the server-side JS interpreters used by Matrix have a CLI utility, if you need one.

V8JS has d8, while Spidermonkey will have one or more of:

  • js
  • js17
  • js24
  • js31
  • js38
  • js45

(Nic Hubbard) #3

But this isn’t something that could be setup on in the Matrix interface? It would have to be done on the server side?


(Marcus Fong) #4

Yes, that’s right.

If you need a solution within Matrix, there’s a trigger action for Call REST Resource - maybe you could do something with that?

https://matrix.squiz.net/manuals/triggers/chapters/trigger-actions#Call-REST-Resource


(Nic Hubbard) #5

Would there be any way that this trigger could be run at an interval such as once each day?


(Marcus Fong) #6

As far as I know, the only trigger event fired by cron is the Metadata Time event, which is fired by the Metadata Triggers cron job which runs every 15 minutes:

https://matrix.squiz.net/manuals/triggers/chapters/trigger-events#Metadata-Time

Perhaps if you used that trigger event together with the Metedata Time trigger condition and the Set Metadata Field Date trigger action, you could create a recurring trigger?

https://matrix.squiz.net/manuals/triggers/chapters/trigger-conditions#Metadata-Time
https://matrix.squiz.net/manuals/triggers/chapters/trigger-actions#Set-Metadata-Field-Date


(Bart Banda) #7

Yep, you could use the metadata time trigger event and then have a condition of keyword matching to check the current time. For example use %globals_date% (with some appropriate date modifier) to check if the current time is 12:00:00 or something.