Page 1 of 1

Trigger Application Cleanup

Posted: Wed Jun 26, 2024 2:41 pm
by JimmyHartington
Is there a way to trigger the Application Cleanup in Switch in a flow?

In one of my flows I do some cleanup of files available in a Checkpoint.
This happens with an Inject Wildcard element. So the file is moved from the Checkpoint backing folder.
And this does not force an update in the web-client of the Checkpoint. This only happens if I run the Application Cleanup manually.

So if I do not run the cleanup my users end up seeing duplicates.
Image

Re: Trigger Application Cleanup

Posted: Wed Jun 26, 2024 3:03 pm
by r.zegwaard
Following...

Re: Trigger Application Cleanup

Posted: Wed Jun 26, 2024 7:54 pm
by magnussandstrom
I guess you struggeling with a similar problem as Vitor?

viewtopic.php?t=5069

Re: Trigger Application Cleanup

Posted: Wed Jun 26, 2024 9:32 pm
by JimmyHartington
Some of it is the same in regards to seeing a "ghost" job in the Switch Portal.
But I can not use the replace job.
Because some files are removed from other flows where some processing has been done.

Re: Trigger Application Cleanup

Posted: Thu Jun 27, 2024 8:55 am
by freddyp
The conceptually correct way of removing a job from a checkpoint is to provide an outgoing connection e.g. called "Has been replaced", and to route the job to that output using the Switch REST API: https://www.enfocus.com/manuals/Develop ... b-RouteJob

Re: Trigger Application Cleanup

Posted: Thu Jun 27, 2024 9:18 am
by JimmyHartington
So in my case where I right now find a file in a folder based on the filename, this would be the process?
  • Call the API to list jobs in a certain checkpoint.
  • In this list find the job by filename.
  • Get the ID.
  • Use the ID to route the job through the right connector.

Re: Trigger Application Cleanup

Posted: Thu Jun 27, 2024 10:14 am
by freddyp
I have never done this myself, but from looking at the documentation I would say It is the other way around: you start from the job. That should not be problem because you know the ID of the job. There is a call to list the properties of a job (Client module-Jobs-List). In the return value there is a field with the ID of the checkpoint where the job sits (if applicable) and all the IDs of the outgoing connections, well basically everything you need.

I have some code lying around how to encrypt the password for logging in to the Switch REST API so you do not have to figure that out:

Code: Select all

const crypto = require("crypto");

//make sure this is not prettified and spaces are added to the beginning of the lines!!!!
const switchPublicKey = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/ZW93qx1U6iGDwFWjYRpgS6/l
vFV/VGEM7wV14Gr4ZZxpZto3rpot3As4Cn0a++LwVh1oSidmiRWnHcKBDCmov8IL
fJ6SckFV41WZWibx8eSTCfn6zlrQ6QgJC2jdpLbWewxhox58zVXk5iK67GOKqbE/
HzSFJVdqIyjNX0/IpQIDAQAB
-----END PUBLIC KEY-----`;

  //encryption of the password to be included somewhere in your code
  let password = "probably comes from a property";
  const buffer = Buffer.from(password);
  const encryptObj = {key: switchPublicKey, padding: crypto.constants.RSA_PKCS1_PADDING};
  const encrypted = crypto.publicEncrypt(encryptObj, buffer);
  const b64 = encrypted.toString("base64");
  password = "!@$" + b64;

Re: Trigger Application Cleanup

Posted: Thu Jun 27, 2024 10:42 am
by JimmyHartington
In my case it is a new job, which triggers the removal of another job in a checkpoint.
So I do not know the ID of the job at the checkpoint.
I also has 5 checkpoints where a job can reside at a given point in time.

But thanks for the code. I will try look into it when I have more time on hand.

Re: Trigger Application Cleanup

Posted: Thu Jun 27, 2024 11:17 am
by freddyp
Right, but if you do not specify an ID when listing jobs you get them all and you can loop over them and filter out the ones that are in a checkpoint, etc.