A script instead of a trigger?

The description of Daml Script frames it as suitable for testing, feedback in Daml studio and initializing data on the ledger. But it is not discussed it in the context of performing periodic tasks against the ledger. Can it be used in that context too?

One thing that is particularly nice is that you can run a script against the HTTP-JSON server; you can off load your state management to it completely and query for what you want. This is different from a trigger where I would need to maintain them in the ACS. If I want to run something once a week or less frequently, what’s the benefit of a trigger vs a script?

For example, if I want to periodically inspect my ACS, find all templates of a give type and exercise a choice on them, say they are old invitations that I want to archive, would that be better done as a script?

I think calling a script from a cronjob is perfectly reasonable. Keep in mind though that things like query can be relatively inefficient because they don’t allow for fine-grained server-side filtering so if that becomes an issue you probably want to build something on your own and keep a custom index or something along those lines.

What I would not recommend is to have the script itself run as a long-running process. While this should work technically scripts haven’t really been built or tested for that extensively and I think you’re better off relying on standard things like cron to invoke the script periodically.

1 Like

Yea, I do wish that queryFilter actually filtered on the server side.