Hello,

All you need to do is just  this call in your event handler

    my $Success = $Object->AsyncCall(
        ObjectName               => 'Kernel::System::Ticket',   # optional, if not given the object is used from where
                                                                # this function was called
        FunctionName             => 'MyFunction',               # the name of the function to execute
        FunctionParams           => \%MyParams,                 # a ref with the required parameters for the function
        Attempts                 => 3,                          # optional, default: 1, number of tries to lock the
                                                                #   task by the scheduler
        MaximumParallelInstances => 1,                          # optional, default: 0 (unlimited), number of same
                                                                #   function calls from the same object that can be
                                                                #   executed at the the same time
    );

This verifies that the object exists and that can execute the function, after that it create a task for the Daemon.

Then the Daemon read the task and execute it.

For the documentation issues please rise a bug report, apparently that part was not updated from 4 to 5.

((enjoy))

Carlos Rodríguez




On Jul 25, 2016, at 3:40 AM, Moritz Lenz <moritz.lenz@noris.de> wrote:

Hi,

On 25.07.2016 10:02, Juan Manuel Clavero Almirón wrote:
Hi all,



I have an event module that takes too much time so the user response
time is ridiculous. I was thinking of creating a new asynchronous task
from the event and then run the actions on the background.



I’ve been reading the OTRS 5.0 dev manual : it refers to the task
handler and shows a test module located in
Kernel/Scheduler/TaskHandler/Test.pm, but my OTRS install doesn’t have
any Scheduler folder.



The admin manual refers to the OTRS Daemon, new feature in OTRS 5, and
I’ve located some modules in the System folder, but I cannot find any
document on how to create a new process for the daemon.

https://otrs.github.io/doc/manual/developer/stable/en/html/architecture-overview.html#Scheduler-TaskHandler
talks about
$OTRS_HOME/Kernel/Scheduler/TaskHandler/GenericInterface.pm, but I think
the proper location is
$OTRS_HOME/Kernel/System/Daemon/DaemonModules/SchedulerTaskWorker/GenericInterface.pm

But I don't think you have to actually touch any of the DaemonModules,
the existing AsynchronousExecutor should do just fine.

Can anybody refer to some guide or explain how to register a new
asynchronous task?

Here is an example of a task that is being executed asynchronously:

https://github.com/OTRS/otrs/blob/43abbee47642a486177bb4ffe39c3677bdcaca52/Kernel/System/Web/InterfaceAgent.pm#L385-L394

So one thing you could do is to write an ordinary, synchronous event
that, like the example above, calls TaskAdd with Type =>
'AsynchronousExecutor' on a Kernel::System::Scheduler object. And
another function which does the slow work you need to do, and then the
Scheduler executes that for you in the background.

Of course, that's all a very indirect way to approach that (but one that
works without patching OTRS itself).

I'd rather see a patch to Kernel::System::EventHandler that directly
supports asynchronous execution, so that you could get rid of a writing
a synchronous event that just triggers an asynchronous task.

Best regards,
Moritz
_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/mailman/listinfo/dev