Saltar a contenido

Estoy empezando ahora

Si estás empezando ahora con BotCity o quieres tener una idea general de cómo se pueden reportar los elementos procesados en el código del proceso, simplemente sigue la guía a continuación:

Utilizando el SDK de Maestro para reportar datos

Puedes reportar fácilmente la información sobre los elementos que han sido procesados utilizando el SDK de Maestro en el código de tu automatización.

Instalación del SDK

Si aún no tienes la dependencia instalada, simplemente sigue estas instrucciones:

pip install botcity-maestro-sdk

Importante

Además de instalarlo, recuerda incluir la dependencia en el archivo requirements.txt del robot.

<repositories>
    <repository>
        <id>nexus-botcity-public</id>
        <url>https://devtools.botcity.dev:8081/repository/botcity-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <!-- Your other dependencies -->
    <dependency>
        <groupId>dev.botcity</groupId>
        <artifactId>maestro-sdk</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>

Importando el SDK

Después de la instalación, simplemente importa la dependencia e instancia el SDK de Maestro:

# Importing the Maestro SDK dependency
from botcity.maestro import *

# Disabling errors if there is no connection with Maestro
BotMaestroSDK.RAISE_NOT_CONNECTED = False

# Instantiating the Maestro SDK
maestro = BotMaestroSDK.from_sys_args()
# Getting the details of the current task being executed
execution = maestro.get_execution()
// Importing the Maestro SDK dependency
import dev.botcity.maestro_sdk.*;
...

public void action(BotExecution botExecution) {

    try {
        // Instantiating the Maestro SDK
        BotMaestroSDK maestro = new BotMaestroSDK();
        maestro.login(botExecution);
    ...

Reportando los datos del proceso

Al final de la ejecución, es posible reportar en la finalización de la tarea la información sobre los elementos que han sido procesados.

maestro.finish_task(
    task_id=execution.task_id,
    status=AutomationTaskFinishStatus.SUCCESS,
    message="Task Finished OK.",
    total_items=100, # Total number of items processed
    processed_items=90 # Number of items processed successfully
)
maestro.finishTask(
    botExecution.getTaskId(),
    "Task Finished OK.",
    FinishStatus.SUCCESS,
    100, // Total number of items processed
    90, // Number of items processed successfully
    10 // Number of items processed with failure
);

Código completo

from botcity.core import DesktopBot
from botcity.maestro import *

# Disabling errors if there is no connection with Maestro
BotMaestroSDK.RAISE_NOT_CONNECTED = False

def main():
    maestro = BotMaestroSDK.from_sys_args()
    execution = maestro.get_execution()

    # Implementing here the logic to process the items
    bot = DesktopBot()

    # The items can be any entity related to your automation process
    items = []
    processed_items = 0
    failed_items = 0

    # You can use the logic that is necessary to consume, process, and count the items
    for item in items:
        try:
            # Process the item...

            # Counting as an item processed successfully
            processed_items+=1

        except Exception:
            # Counting as an item processed with failure
            failed_items+=1

    # At the end, simply report the data of the processed items when finishing the task
    maestro.finish_task(
        task_id=execution.task_id,
        status=AutomationTaskFinishStatus.SUCCESS,
        message="Task Finished OK.",
        total_items=len(items), # Total number of items processed
        processed_items=processed_items, # Number of items processed successfully
        failed_items=failed_items # Number of items processed with failure
    )

def not_found(label):
    print(f"Element not found: {label}")

if __name__ == '__main__':
    main()
import java.util.List;
import java.util.ArrayList;
import dev.botcity.framework.bot.DesktopBot;
import dev.botcity.maestro_sdk.BotExecutor;
import dev.botcity.maestro_sdk.BotMaestroSDK;
import dev.botcity.maestro_sdk.model.AutomationTask.FinishStatus;
import dev.botcity.maestro_sdk.runner.BotExecution;
import dev.botcity.maestro_sdk.runner.RunnableAgent;

public class FirstBot extends DesktopBot implements RunnableAgent
{
    public FirstBot() {
        try {
            setResourceClassLoader(this.getClass().getClassLoader());
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void action(BotExecution botExecution) {

        try {
            BotMaestroSDK maestro = new BotMaestroSDK();
            maestro.login(botExecution);

            // The items can be any entity related to your automation process
            List<Object> items = new ArrayList<Object>();
            int processedItems = 0;
            int failedItems = 0;

            // You can use the logic that is necessary to consume, process, and count the items
            for(Object item : items){
                try{
                    // Process the item...

                    // Counting as an item processed successfully
                    processedItems+=1;
                }
                catch(Exception e){
                    // Counting as an item processed with failure
                    failedItems+=1;
                }
            }

            // At the end, simply report the data of the processed items when finishing the task
            maestro.finishTask(
                botExecution.getTaskId(),
                "Task Finished OK.",
                FinishStatus.SUCCESS,
                items.size(), // Total number of items processed
                processedItems, // Number of items processed successfully
                failedItems // Number of items processed with failure
            );

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    private void notFound(String label) {
        System.out.println("Element not found: "+label);
    }

    public static void main(String[] args) {
        BotExecutor.run(new FirstBot(), args);
    }
}

Consejo

No es obligatorio utilizar una estructura de código específica en tu proceso de automatización.

Tienes total libertad para definir la lógica que se utilizará y también la forma en que se contabilizarán los elementos.

Al final, simplemente reporta estos datos utilizando el método finish_task del SDK de Maestro.