I've noticed that tasks only run when logged into the admin panel, is there anyway to avoid this?
For some context: I have jobs scheduled on a cron to run every 30 minutes, when I log in it seems that all of the items get queued up from the last time I logged in and proceed to run, this isn't terrible - but this app won't be seeing much login activity down the road.
`public function execute($queue)
{
$section = Craft::$app->sections->getSectionByHandle('orders');
$entryTypes = $section->getEntryTypes();
$entryType = reset($entryTypes);
// Create an entry
$entry = new Entry([
'sectionId' => $section->id,
'typeId' => $entryType->id,
'fieldLayoutId' => $entryType->fieldLayoutId,
'authorId' => 1,
'title' => 'Order Number: ' . $this->orderId,
'slug' => $this->orderId,
'postDate' => new DateTime(),
]);
$entry->setFieldValues([
'orderId' => $this->orderId,
'lineItemMatrix' => $this->lineItemMatrix,
'couponMatrix' => $this->couponMatrix,
'amountPayable' => $this->amountPayable,
'orderTotal' => $this->orderTotal,
'tax' => $this->tax,
'sellerDiscount' => $this->sellerDiscount,
'shipping' => $this->shipping
]);
//check to see if entry exists.
$existing = Entry::find()->section('orders')->slug($entry->slug)->one();
if (is_null($existing)){
return Craft::$app->elements->saveElement($entry);
} else {
// don't do anything;
return false;
}
}`
./craft queue/listenwhich starts a process that polls the queue, and runs things as needed; see yiisoft/yii2-queue. – andrew.welch Nov 30 '18 at 21:19./craft queue/run) from a cron task. Thelistenmethod is appropriate when you're OK daemonizing it (or, as on Heroku, you have a "worker" dyno), but if the setup is daunting, cron would be totally suitable. – August Miller Dec 11 '18 at 22:09bodytag), if there are pending jobs in the queue… – August Miller Dec 11 '18 at 22:12