0

I am trying to get my head around the TaskService that Craft comes with. I want to create a task that periodically (say every 15 minutes) uses the Twitter API. I am currently creating a task modeled on Pixel & Tonic's PowerNap which was very helpful, but I still don't understand how the tasks are triggered.

In the createTask method I didn't see any duration or anything like that and if the tasks are created within a controller that would have to be posted to, would this require a tandom cron job to trigger it from the server?

Any clarifications, insights, or references that might be helpful in better understanding the TaskService would be greatly appreciated as the Class Reference's docs aren't really that helpful.

Thanks!

3

Craft's tasks are meant for long-running PHP requests and don't have to execute immediately. By default when you create a new task, it is queued in the database in the craft_tasks table and it takes a control panel request to trigger it to run, so with that method, there's no guaranteed way to have it run every 15 minutes.

However, if you set the runTasksAutomatically config setting to false, then you can setup an cron job that runs at any interval you wish. You'd point it to a controller action on your plugin and manually trigger the task that way.

| improve this answer | |
  • So there's no repeat-scheduling available in Craft then? All scheduling has to be done in Cron? – Simon East Jun 14 '17 at 23:25
  • @SimonEast Correct. – Brad Bell Jun 14 '17 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.