Adriano Faria Posted August 12, 2019 Posted August 12, 2019 Hello, I have a Queue extension on installOther(): public function installOther() { if( \IPS\Db::i()->checkForColumn( 'core_members', 'membersaway_on' ) ) { \IPS\Task::queue( 'memberaway', 'Away', array(), 1 ); } } The queue itself: class _Away { /** * @brief Number of members to run per cycle */ public $rebuild = \IPS\REBUILD_NORMAL; /** * Parse data before queuing * * @param array $data * @return array */ public function preQueueData( $data ) { return $data; } /** * Run Background Task * * @param mixed $data Data as it was passed to \IPS\Task::queue() * @param int $offset Offset * @return int New offset * @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete */ public function run( $data, $offset ) { $select = \IPS\Db::i()->select( 'member_id, membersaway_on, membersaway_text, membersaway_days, membersaway_date', 'core_members', array( 'membersaway_on=?', 1 ), 'member_id ASC', array( $offset, $this->rebuild ) ); if( !$select->count() ) { throw new \IPS\Task\Queue\OutOfRangeException; } foreach( $select as $row ) { \IPS\memberaway\Status::setMemberData( $row['member_id'], $row['membersaway_on'], $row['membersaway_text'], $row['membersaway_days'], $row['membersaway_date'] ); } return $offset + $this->rebuild; } /** * Get Progress * * @param mixed $data Data as it was passed to \IPS\Task::queue() * @param int $offset Offset * @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete * @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete */ public function getProgress( $data, $offset ) { return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'ma_rebuilding_members_data', FALSE ), 'complete' => ( isset( $data['count'] ) AND $data['count'] ) ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 ); } /** * Perform post-completion processing * * @param array $data * @return void */ public function postComplete( $data ) { try { $pluginData = \IPS\Db::i()->select( '*', 'core_plugins', array( 'plugin_location=?', "memberaway" ) )->first(); try { $plugin = \IPS\Plugin::load( $pluginData['plugin_id'] ); $plugin->delete(); } catch ( \Exception $e ){} } catch( \UnderflowException $e ){} } } \IPS\memberaway\Status::setMemberData() used in Queue: public static function setMemberData( $memberId, $status, $text, $days, $date ) { \IPS\Db::i()->replace( 'memberaway_data', array( 'ma_mid' => $memberId, 'ma_on' => $status, 'ma_text' => $text, 'ma_days' => $days, 'ma_date' => $date ) ); } Happens that the Queue gets stuck in 100% on dashboard: I don't think there's erros because if I run it manually by clicking in the link from the message above, it runs just fine. I also tried to change the priority in the Queue but no luck. Is there anything wrong in my code? Tks. 👍 No error in the logs.
newbie LAC Posted August 12, 2019 Posted August 12, 2019 Hello, return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'ma_rebuilding_members_data', FALSE ), 'complete' => ( isset( $data['count'] ) AND $data['count'] ) ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 ); I don't see where you defined $data['count'] So the condition looks like return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack( 'ma_rebuilding_members_data', FALSE ), 'complete' => 100 ); always 100%
Adriano Faria Posted August 12, 2019 Author Posted August 12, 2019 Oh yes... my bad. /** * Parse data before queuing * * @param array $data * @return array */ public function preQueueData( $data ) { $data['count'] = \IPS\Db::i()->select( 'count(*)', 'core_members', array( 'membersaway_on=?', 1 ) )->first(); return $data; } Now I got stuck in 0%. $data['count'] returns 1 in getProgress(), which is right. I have only 1 record in a test. core_queue table: The only difference now is that I changed the the key to Away instead of memberAway. Manually it works just fine.
newbie LAC Posted August 14, 2019 Posted August 14, 2019 The reason is that during installation the application is disabled and enabled on the finished step But the queue runs for enabled apps So your queue is stopped Enable your application before run queue To IPS developers: - Any reason why you use $application->enabled = 1; $application->save(); instead of $application->_enabled = 1; $application->save(); - The installHooks method calls twice 1 call /* Rebuild data */ \IPS\Application::load( $data['key'] )->installJsonData(); /** * Rebuild common data during an install or upgrade. This is a shortcut method which * * Installs module data from JSON file * * Installs task data from JSON file * * Installs setting data from JSON file * * Installs ACP live search keywords from JSON file * * Installs hooks from JSON file * * Updates latest version in the database * * @param bool $skipMember Skip clearing member cache clearing * @return void */ public function installJsonData( $skipMember=FALSE ) { ................ /* Rebuild hooks */ $this->installHooks(); 2 call /* Install hooks - do this after enabling the application */ $application->installHooks();
Adriano Faria Posted August 14, 2019 Author Posted August 14, 2019 5 hours ago, newbie LAC said: Enable your application before run queue Perfect. Thank you. 👍
Recommended Posts
Archived
This topic is now archived and is closed to further replies.