Timeout with performSmartRule

Since you mention „timeout“ in the title of the post: You can set a timeout value when calling JXA functions. Apple’s JXA documentation mentions that (and I don’t remember the exact semantics), so you should be able to find it there.

If setting that doesn’t help, I’d suggest to pepper your 2nd external script with app.logMessage() calls or something similar so that you can at least get an idea up to which point it runs.

1 Like

Ah well; recognising patterns, clutching at straws :man_shrugging:t3: Thx for the feedback :+1:t3:

I’ve created a simplified JXA test script. It seems this has the same result: when I try to trigger the script via AppleScript or JXA with perform smart rule or app.performSmartRule() it gives a timeout (DT3.8.6). Wondering if you get the samen results with this @chrillek @blanc? Btw: it doesn’t seem to matter if it’s an internal or external JXA script.

function performsmartrule(records) {

	const app = Application("DEVONthink 3");
	app.includeStandardAdditions = true;
	app.logMessage("Starting Annotation Process incoming JS");
	app.showProgressIndicator("Processing incoming item", { steps: records.length, cancelButton: false });

	records.forEach(r => {
		app.stepProgressIndicator(r.name());
	});

	app.hideProgressIndicator();
	app.logMessage("Done Annotation Process incoming JS");
}

I can’t test before the end of next week, since I’m away from my Mac with the DT install.

However: Do you see any of the log messages?

No, none with the above script. As soon as it triggers it starts beachballing.

When trying with a rule which executes a simple inline AppleScript there are no problems:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			log message "Test"
		end repeat
	end tell
end performSmartRule

Seems it’s definitely (another) JXA quirk?

For debugging purposes, this is what I have:

When trying to run this smart rule (with 2 items matched) e.g. via Applescript using

tell application id "DNtp"
	perform smart rule name "Resources: process inbox"
end tell

… it will beachball immediately, hold the whole app and eventually time out. It also seems very similar to this issue @Lynx was having a while back: Error "on performSmartRule (Error: Error: AppleEvent timed out.)" when running a smart rule wit a javascript script every minute - #13 by mdbraber

Thanks for persevering :+1:t3: I also cannot currently test; if it’s reproducibly beach balling though, that is excellent. Criss @cgrunenberg will ask you to sample the process and send him the result, and then - if past performance is any indication of future performance - he’ll come here and go “fixed for the next release” :slight_smile:

Thanks - I’ve send the debug logs to development@devontechnologies.com

Do you have other smart rules also targeting the Global Inbox?

No all other smart rules are disabled.

But are there any that target the Global Inbox, inactive or not?

There were others which targeted the same inbox as this rule (Resources > Inbox). None which targeted the Global Inbox. I’ve now removed all other smart rules and just kept this one. Restarted DT. Same result.

It’s a timeout caused by one AppleEvent waiting for another one. The next release will include a workaround but actually it’s recommended to directly call the scripts in this case instead of indirectly via smart rules.

1 Like

@cgrunenberg thanks for identifying the bug. I’ll check how I can run the script directly. Does this mean you’re actually advising against calling perform smart rule or app.performSmartRule() with smart rules running external scripts?

Yes, that’s recommended.

I forgot to add probably, but the timeout also happens when the smart rule is triggered by anything other than ‘on demand’ (same problem as @Lynx). So e.g. it also times out when “On import” is triggered because an item is added to the Inbox. So I’m eagerly awaiting the fix in the next release (or would there be a beta version to use / test)?

It’s unclear how it’s triggered. Still via perform smart rule?

No it is triggerd via the Actions of the smart rule itself (e.g. On Import, On Creation etc)

In that case it might be an issue of the used script and that it requires too much time for the default AppleEvents timeout of 60 seconds. Using a with timeout of x seconds ... end timeout block might fix this.

Thanks. I’ll investigate also!