ostark / craft-async-queue

Async Queue Handler for Craft 3 and 4
MIT License
93 stars 7 forks source link

Migration error when attempting to upgrate a site that uses async-queue from Craft 3.3.20.1 => 3.4.11. #30

Closed tomdavies closed 4 years ago

tomdavies commented 4 years ago

Hey @ostark 👋,

Plugin version: 2.1.0

Not sure if this a bug, but thought I'd report it just in case. I hit an error when attempting to upgrate a site that uses async-queue from Craft 3.3.20.1 => 3.4.11.

When running ./craft migrate/all I got this error (full stack trace after):

Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'channel' in 'where clause'
The SQL being executed was: UPDATE `queue` SET `dateReserved`=NULL, `timeUpdated`=NULL, `progress`=0, `progressLabel`=NULL WHERE ((`channel`='queue') AND (`fail`=FALSE)) AND (`timeUpdated` < 1585647734 - `ttr`) (/app/vendor/yiisoft/yii2/db/Schema.php:674)

Disabling async-queue and running again (albeit with a fresh database dump) worked, so it's not blocking me any more, just thought you should know about it.

Happy to try and make a reduced test case if that's helpful....

Stack trace:

The SQL being executed was: UPDATE `queue` SET `dateReserved`=NULL, `timeUpdated`=NULL, `progress`=0, `progressLabel`=NULL WHERE ((`channel`='queue') AND (`fail`=FALSE)) AND (`timeUpdated` < 1585647734 - `ttr`) (/app/vendor/yiisoft/yii2/db/Schema.php:674)
#0 /app/vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema->convertException(Object(PDOException), 'UPDATE `queue` ...')
#1 /app/vendor/yiisoft/yii2/db/Command.php(1093): yii\db\Command->internalExecute('UPDATE `queue` ...')
#2 /app/vendor/craftcms/cms/src/queue/Queue.php(653): yii\db\Command->execute()
#3 /app/vendor/craftcms/cms/src/queue/Queue.php(341): craft\queue\Queue->_moveExpired()
#4 /app/vendor/ostark/craft-async-queue/src/RateLimiter.php(39): craft\queue\Queue->getTotalReserved()
#5 /app/vendor/ostark/craft-async-queue/src/Handlers/BackgroundQueueHandler.php(36): ostark\AsyncQueue\RateLimiter->canIUse('Resaving elemen...')
#6 [internal function]: ostark\AsyncQueue\Handlers\BackgroundQueueHandler->__invoke(Object(yii\queue\PushEvent))
#7 /app/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(ostark\AsyncQueue\Handlers\BackgroundQueueHandler), Object(yii\queue\PushEvent))
#8 /app/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\queue\\Que...', 'afterPush', Object(yii\queue\PushEvent))
#9 /app/vendor/yiisoft/yii2-queue/src/Queue.php(197): yii\base\Component->trigger('afterPush', Object(yii\queue\PushEvent))
#10 /app/vendor/craftcms/cms/src/queue/Queue.php(174): yii\queue\Queue->push(Object(craft\queue\jobs\ResaveElements))
#11 /app/vendor/verbb/navigation/src/services/Nodes.php(150): craft\queue\Queue->push(Object(craft\queue\jobs\ResaveElements))
#12 [internal function]: verbb\navigation\services\Nodes->afterSaveSiteHandler(Object(craft\events\SiteEvent))
#13 /app/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\events\SiteEvent))
#14 /app/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\services\\...', 'afterSaveSite', Object(craft\events\SiteEvent))
#15 /app/vendor/craftcms/cms/src/services/Sites.php(795): yii\base\Component->trigger('afterSaveSite', Object(craft\events\SiteEvent))
#16 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(1099): craft\services\Sites->handleChangedSite(Object(craft\events\ConfigEvent))
#17 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#18 /app/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#19 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(675): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#20 /app/vendor/craftcms/cms/src/helpers/ProjectConfig.php(89): craft\services\ProjectConfig->processConfigChanges('sites.1fae7cf9-...')
#21 /app/vendor/craftcms/cms/src/services/Sections.php(595): craft\helpers\ProjectConfig::ensureAllSitesProcessed()
#22 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(1099): craft\services\Sections->handleChangedSection(Object(craft\events\ConfigEvent))
#23 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#24 /app/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#25 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(675): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#26 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(1089): craft\services\ProjectConfig->processConfigChanges('sections.0b8ab5...')
#27 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#28 /app/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#29 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(672): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#30 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(489): craft\services\ProjectConfig->processConfigChanges('sections.0b8ab5...', true, '')
#31 /app/vendor/craftcms/cms/src/migrations/m190913_152146_update_preview_targets.php(54): craft\services\ProjectConfig->set('sections.0b8ab5...', Array)
#32 /app/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m190913_152146_update_preview_targets->safeUp()
#33 /app/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration->up(true)
#34 /app/vendor/craftcms/cms/src/db/MigrationManager.php(153): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m190913_152146_update_preview_targets))
#35 /app/vendor/craftcms/cms/src/services/Updates.php(225): craft\db\MigrationManager->up()
#36 /app/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#37 [internal function]: craft\console\controllers\MigrateController->actionAll()
#38 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#39 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#40 /app/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('all', Array)
#41 /app/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#42 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#43 /app/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#44 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#45 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#46 /app/craft(22): yii\base\Application->run()
#47 {main}
Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Craft CMS.'

in /app/vendor/craftcms/cms/src/services/Updates.php:241

Stack trace:
#0 /app/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#1 [internal function]: craft\console\controllers\MigrateController->actionAll()
#2 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#4 /app/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('all', Array)
#5 /app/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#6 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#7 /app/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#8 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#9 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#10 /app/craft(22): yii\base\Application->run()
#11 {main}
ostark commented 4 years ago

This migration comes from craft core

tomdavies commented 4 years ago

@ostark , sorry maybe I wasn’t clear. I know it’s a core migration, but the migration breaks if this plugin is installed/enabled. If the plugin is disabled the migration works, so it must be something in the plugin code that causes the error, no?

ostark commented 4 years ago

Sorry, I can not imagine a relation

josephkerkhof commented 4 years ago

Hello,

I'd like to say I'm experiencing almost exactly the same problem that @tomdavies is describing. I am upgrading Craft from 3.3.6 => 3.4.12 and craft-async-queue from 1.4 => 2.1.

I am getting an almost identical stack trace as @tomdavies as it looks like some async-queue code is running (See stack trace on 4 and 5) during the Craft migration.

If I disable the async-queue plugin before running the Craft migration scripts, the migration completes successfully. I can then re-enable the craft-async-queue plugin on the upgraded site.

ostark commented 4 years ago

Ah, it's a chicken egg problem. The migration adds a new 'channel' field to the queue table and fires an event that injects a job to the queue which makes use of the new field.

ostark commented 4 years ago

https://github.com/ostark/craft-async-queue/releases/tag/2.1.1 thanks, this should fix it

josephkerkhof commented 4 years ago

Thanks for the quick fix @ostark! I've run my migration scripts locally a few times now and that update seems to be fixing it for me.

Cheers! 🍻

tomdavies commented 4 years ago

Yeah I had a similar thing with Neo and the same upgrade. Events are a pain the arse

Tom Davies tom@tomdavies.net

On 3 Apr 2020, at 20:05, Oliver Stark notifications@github.com wrote:

 Ah, it's a chicken egg problem. The migration adds a new field and fires a event that injects a job to the queue which makes use of the new field.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.