Skip to content

queue API methods customTask

hannsolo edited this page May 6, 2020 · 2 revisions

public runCustom(scope: any, fn: ( client: FSIServerClient, queue: Queue, fnProgress: (taskDescription: string, pos: number, length: number) => void, ...args: any[]) => Promise, ...args: any[]): void ~> Promise<boolean>

Iterates over all files and folders currently collected in the queue and calls the custom function for each entry. This way you can accomplish any batch task not covered by the queue API.

const client = new FSIServerClient('https://my.fsi-server.tld');
client.setLogLevel(FSIServerClient.LogLevel.info);
const queue = client.createQueue({
    continueOnError: false,
    fnProgress: FSIServerClient.defaultProgress
});

const myCustomFunction = (theClient, theQueue, fnProgress, foo, bar) => {
    return new Promise((resolve) => {
        console.log("Running custom function:");
        console.log("foo is: " + foo + " bar is: " + bar);
        const content = theQueue.getCurrentBatchContent();
        if (content) {
            console.log("batch contains " + content.entries.length + " items.");
            for (let i = 0; i < content.entries.length; i++) {
                const msg = "Doing something with entry \"" + content.entries[i].src + "\"";
                fnProgress.call(theQueue, msg, i, content.entries.length);
            }
        }
        else {
            console.log("batch is empty.");
        }
        resolve(true);
    });
};

// start session
queue.login("user", "password);

// list dir content
queue.listServer("images/foo", {
    recursive: false
});

// run the custom task "myCustomFunction" in "global" scope
queue.runCustom(global, myCustomFunction, 123, "foo arg");

// close session
queue.logout();

// run the queued commands
queue.runWithResult();

Note: the methods above just add the commands to the queue. Execution starts when calling queue.run() or queue.runWithResults().
Clone this wiki locally