Delayed_Job NoMethodError when using Nginx - nginx

I'm having trouble implementing the Delayed_Job_Active_Record gem in my Production Environment with Nginx. The user submits a 'Contact Us' form, the relevant controller action is called by Nginx and the following line of code fails:
#contact.delay.send_contact_form
Where the relevant method is:
def send_contact_form
ContactMailer.contact_us(self).deliver
end
Development Env: OK
On my local machine I have the pages served by Webrick. Everything runs fine, the delayed jobs go through the 'Delayed_Jobs' table and emails are sent.
Production Env - Rails Console: OK
On the server if I create #contact and call #contact.delay.send_contact_form manually, the delayed job goes through the delayed job table and email is sent.
Production Env - Webrick: OK
On the server if I start up a rails Webrick server I and enter the data for #contact via the web interface and then submit the job goes through the delayed job table and email is sent.
Production Env - Nginx: ERROR
The application is currently served by Nginx.
If I visit the interface via Nginx and enter the data for #contact and submit the page hangs.
The Production Log gives the following error on the controller action, (referencing the line above):
NoMethodError (undefined method `delay' for #< Contact:0x000000052962b0>)
I have also confirmed that the versions of Rails, Ruby and the Delayed_Job_Active_Record and Daemons gems are the same in both environments.
Any help would be greatly appreciated as i've been stuck on this one for a while. I want to find a solution that works with Nginx and which gives me the same functionality as 'Delayed Job'.
Thanks.

It turns out the problem was with Unicorn/Nginx not being restarted upon deployment of code updates, leaving them with incorrect configurations. The problem also occurred when adding Devise and other gems to the application.
The solution initially was to log into the VPS shell after a deployment, (via Capistrano) and run the following:
Restart Unicorn:
/etc/init.d/unicorn_esg stop
/etc/init.d/unicorn_esg start
Where *unicorn_esg* is the Unicorn reference to the application used in my deploy.rb configuration.
Restart Nginx:
sudo service nginx restart
The next step would be to incorporate this into the end of the deploy.rb script so it is automatically run at the end of each deployment.

Related

I try to deploy my process and I have wrong rest endpoint

I try to deploy my process and I have wrong rest endpoint,I can't press the deploy button
what is my problem?
Well there are two basic problems that come to my mind.
You didn't start camunda. If you are connecting to camunda through an app make sure that it's running. Try deploying again after your app is running successfully.
You are using the wrong port. Make sure that camunda is running on port 8081 as you stated on your endpoint. You can check whether the port is used or not by entering the netstat -an command to windows cmd. Something with :8081 should show up if it's used.
If you using an unmodified recent Camunda version then your REST endpoint URL is:
http://localhost:8080/engine-rest
Of course the server needs to be started / have started without errors.
Please also see:
How to deploy a Camunda modeled diagram into Camunda Tomcat

Hip hop error log showing syntax errors and deployment process getting stuck on doing hot deployment parallely (allAtATime) via AWS Codedeploy

We tried this POC to deploy code via AWS Code deploy on 20 live servers, which are behind Load balancer. We are having nginx running in front of Hiphop. We tried hot deployment, i.e. deploying while nginx was running.
As soon as the deployment process moves the new file to the designated place in the production servers, we start getting the following errors, which continues indefinitely on some servers, and the Jenkins jobs times out after polling for 50 minutes -
\nFatal error: syntax error, unexpected $end in /path/to/file.php on line 19477
It appears like only a part of the file gets loaded and read, even though the file in its entirety has no syntax errors.
Restarting nginx on such servers manually fixes the problem, but that does not seem to be a good solution.
We are trying to find out the reason behind this issue.
HHVM version being used - HipHop VM 3.12.0-dev (rel)
Nginx version - 1.8.0
Alternative approach
We are now trying to do cold deployment (shut down nginx then do deployment and then turn on nginx again), but that too is throwing its own issues. I will not post those details here, but the idea is to take the advantage of the large number of servers we have, and do cold deployment in such a way that only a small percentage of the servers behind LB have nginx off at a time, so that it does not cause too much load on the running servers.
CodeDeploy will indeed replace files during a deployment. I recommend you try your approach of doing a cold deployment in which you fully shut down before deploying and startup again after it's done.

Xdebug can debug codeception but not codeception tests

I am running Codeception tests in a Symfony2 project and I am developing in PHPstorm.
Debugging codeception used to work, but i recently started a new project it doesn't anymore. Everything is configured as it should. When I set phpstorm to start listening for connections, and I set a breakpoint in bin/codecept. The debugger halts at the breakpoint (as it should).
But when I set the breakpoint in a test (which is definetly ran), I get the message
16:10:41 Debug session was finished without being paused
It may be caused by path mappings misconfiguration or not synchronized local and remote projects.
To figure out the problem check path mappings configuration for 'null' server at PHP|Servers or enable Break at first line in PHP scripts option (from Run menu).
Do not show again (show balloon)
I do believe that something is going wrong with the path mapping, because my server is running on a symlink, but why does debugging app/console and codeception itself work, but not the tests ?
Probably because of this:
https://github.com/Codeception/Codeception/issues/1636#issuecomment-71205765
test is not executed directly, it is triggered from reflection.

Reloading Connect/Express server code using grunt-contrib-watch and reload option

I need to make sure the server instance always runs the latest code.
Grunt-contrib-watch does reload the watched files, but the server process isn't restarted with the new code, thus old behaviour is still online, new code i.
This Grunt task blai/grunt-express does appear to contain this feature:
serverreload
Setting this option to true will tell express task to start a forever
running server in a child process, and if any of your server scripts
change, the server will be restarted (using a dynamically generated
watch task)
UPDATE: Tried the serverreload option in grunt-express - it doesn't appear to do what I understood, it does not change the running server's code
Any chance to achieve the same feature with gruntjs/grunt-contrib-connect and gruntjs/grunt-contrib-watch?
Example: starting my server from the watch 'tasks' option does run my newest code, but this doesn't appear to be a valid answer (server does not respond to HTTP requests anymore). See my grunt connect gist for more details.

Meteor Up (mup) on EC2 Deployment Different from Local App

On localhost, the app works just fine.
On EC2, the app runs behind nginx. It loads into the browser, but nothing shows up. The browser console displays an Error
TypeError: 'undefined' is not an object (evaluating 'Package["service-configuration"].ServiceConfiguration')
I have no idea how to tackle this problem. Any help appreciated.
EDIT
NGINX is not the problem. The same behavior if I access meteor server directly.
Running "meteor add service-configuration" does fix the above mentioned error, but the absence of the error does not fix the observed behavior, that the app does not render on EC2 whereas it does render when started on localhost. (The error message was the only visible difference between EC2 and localhost. So I suspected that would be the cause. Now that hypothesis must be wrong.) So the problem still persists.
Problem Solved. The Lesson:
Meteor has a debug mode and a production mode. The two may behave differently. On localhost, meteor runs in debug mode per default. On deploy to meteor.com or per mup, the default is production mode. To run meteor in production mode on localhost, run meteor --production.
It looks like you're trying to access the service-configuration configs on your browser.
These are not available client side. This also affects your localhost app but it doesn't break your app (doesn't give you a blank page) because meteor is in debug mode.
In debug mode Meteor files are not concatenated so an error like this would go unnoticed, even if it is thrown on your js console. In production mode the error would halt the rest of your script (since everything is concatenated into a single file)
You need to ensure the code that is doing this only runs on the server side. In general it's not a good idea to have access to the service configuration data on the client side.
Looks like Arunoda and crew are adding a buildOptions.debug setting to the next version of MUP, which should allow you to deploy via MUP and have it act like it's running on localhost. See Arunoda's answer to a related question and (at least for now) documentation for the development version of MUP.

Resources