Write a script that runs the first of each month at midnight - how?

I want to run a very simple script that helps keep our database healthy, once a month on the first of each month at midnight. It is NOT important that it happens at midnight to the millisecond, however, it should most definitely run around that time within reason.

The script is going to call an already made stored procedure, so it should be short and simple, I imagine like this -

import system
system.db.runQuery("CALL sp_dbmaint())")

I just don’t know where I should be putting this or how to get it to trigger on the first of every month. Thoughts?

Perhaps overly simplistic, but you could create an expression tag using:

getDayOfMonth(now())

Then, with a Value Changed event on the tag:

	if currentValue.value == 1:
      import system
      system.db.runQuery("CALL sp_dbmaint())")

It should execute once on the first day of the month (The midnight is implied).

2 Likes

Works for me, it’s what my coworkers suggested too. I just thought maybe Ignition would have some built in “run script X at time Y” feature but I couldn’t find anything like that. Timer was close but not exactly what I needed. Thanks.

There was an item on the ideas portal for ignition, but I can’t find it. That system has been moved to a facebook platform, and I can’t see any of it.

I think this was it:

https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/add-scheduled-triggering-of-custom-actionsevents

1 Like

Yes, that’s it. I can’t log into it anymore – seems to due to a reference to facebook.net. Facebook addresses are blocked at every router I own or control.

2 Likes

Actually this is not working at all. I’ve tried it with system.db.runQuery and with

call = system.db.createSProcCall("sp_dbmaint", database="AntiDLocale")
system.db.execSProcCall(call)

Any idea why it’s not working? I added the tag under the main Tags folder. I want this to run regardless of if a cilent is open.

My goof! Replace currentValue with currentValue.value

I’ll admit it. I forget this three or four times a year. :blush:

currentValue is a “qualified value”, so it has value, quality, and timestamp info.

2 Likes