Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when project has deployments but none are 'completed' #188

Closed
6 tasks done
Patabugen opened this issue Mar 9, 2016 · 3 comments
Closed
6 tasks done

Exception when project has deployments but none are 'completed' #188

Patabugen opened this issue Mar 9, 2016 · 3 comments

Comments

@Patabugen
Copy link
Contributor

Before submitting your issue, please make sure that you've checked all of the checkboxes below.

  • You're running the latest release version of Deployer.
  • Ensure that you're running at least PHP 5.5.9, you can check this by running php -v
  • You've ran composer install --no-dev from the root of your installation.
  • You've ran npm install --production from the root of your installation.
  • You've ran rm -rf bootstrap/cache/* from the root of your installation.
  • You have restarted the queue listener and node socket server.

To help us better understand your issue, please answer the following.

Expected behaviour

Load the Project View page

Actual behaviour

An exception is thrown

Steps to reproduce

I've roughly diagnosed this error and think I've got it right. I setup a project and hit Deploy, it didn't work and I cancelled it (I think with a cleanup through 'artisan'). As a result I have a project with two failed deployments and no completed ones, causing an error when the system tried to find the current deployment.

I suspect the system should load the latest deployment regardless of status (remove the WHERE status clause) as a fix, but I haven't explored any of the workings of the system to be able to be sure of that idea

I now have these deployments in the DB:

mysql> select status, project_id, id from deployments where project_id = 3;
+--------+------------+----+
| status | project_id | id |
+--------+------------+----+
| 3      |          3 |  2 |
|        |          3 |  3 |
+--------+------------+----+
2 rows in set (0.00 sec)

when I load /projects/3 I get an exception thrown from this bit of code:

    /**
     * Determines if the deployment is the latest deployment.
     *
     * @return bool
     */
    public function isCurrent()
    {
        if (!isset(self::$currentDeployment[$this->project_id])) {
            self::$currentDeployment[$this->project_id] = self::where('project_id', $this->project_id)
                                                              ->where('status', self::COMPLETED)
                                                              ->orderBy('id', 'desc')
                                                              ->first();
        }

        return (self::$currentDeployment[$this->project_id]->id === $this->id);
    }

The error is because self::$currentDeployment[$this->project_id] is not an object, because the SQL lookup finds nothing - since there are no deployments with a status of 0.

To work around I manually set the status of one deployment to 0 ( update deployments set status = '0' where id = 3; and now it loads (but thinks it completed).

Environment info

Operating System: Ubuntu 14.04.1
PHP Version: 5.6.18
Node Version: 0.10.25
Database System: mysql
Database Version: 5.5.47
[apache2handler-2016-03-09.log.txt]

Logs (see storage/logs/) or other output that would be helpful

(https://github.com/REBELinBLUE/deployer/files/165231/apache2handler-2016-03-09.log.txt)

@jbrooksuk
Copy link
Contributor

I'm getting this too (latest master).

@REBELinBLUE
Copy link
Owner

I shall take a look at this this evening

@REBELinBLUE
Copy link
Owner

This should be fixed now as the method now tests that there is a current deployment... although I am a bit unsure how the error is happening because isCurrent is only called on a deployment that isSuccessful so there should always be at least one successful deployment when the method is called.

That said, the method shouldn't just assume there is a successful deployment so now it doesn't

REBELinBLUE added a commit that referenced this issue Mar 11, 2016
* master:
  Updated CHANGELOG
  Ran php-cs-fixer
  Added diff-so-fancy
  Ensure there is a current deployment before actually assuming it is an object. Fixes #188
  Remove code climate for now
  Remove unneeded drop
  Moved provisioning to a script
  typo
  Fixes #153 Although I have no idea why the throttling is firing as our servers don't ping the heartbeat that often
  Logrotate is no longer needed, supervisor logs aren't stored in the laravel logs folder by default
  Updated dependencies
  Added a license check - april fools
  Added a license check - april fools
  Added HTTP and Node instructions to Install section
  Added missing class
  Have the update command restart the node socket server
  Have the update command restart the node socket server
jcornide pushed a commit to jcornide/deployer that referenced this issue Mar 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants