Goku
Goku

Reputation: 2139

How to call a task in a helper?

I want to create a button in my application to call a task.

How can I do this with a link_to() in my template for example ?

In routing.yml it is possible to create a route to call the task ?

Upvotes: 0

Views: 37

Answers (1)

j0k
j0k

Reputation: 22756

A task can't be launched from a web environment. The goal of a task is to run in command line. You can't achieve what you want to do like you want to do.

You should take a look at message queue soft for that:

  • on an action (a link for example), add an item into the queue
  • each time an item is added to a queue, it launch an action (can be a task for example)

In your case, your item will tell to the queue manager to launch a particular task.

There are a lot of differents message queue soft around ZeroMQ, Redis, Bernard, AMPQ, etc ..

But you can also built your own using a MySQL database (for example):

  • create a database called todo (with an id, a flag, a task name, a field for parameters)
  • on an action (a link for example), add an item to this table (with all informations)
  • create a todoTask that will:
    • fetch items from this table
    • mark them as processed
    • and launch the task described inside the row (with parameters, etc ..) for each item

Upvotes: 2

Related Questions