Errno::ETIMEDOUT: Connection timed out - connect(2) while post_form - ruby-on-rails-3

I have a strange problem
I run commands as below in local machine successfully.
uri = URI('http://IP/XXX/XXX.php')
res = Net::HTTP.post_form(uri, 'account' => Settings.account, 'orderno' => order.order_no, 'order_money' => order.total_price, 'order_user' => order.name )
success message as below
#<Net::HTTPOK 200 OK readbody=true>
However, after deploy to production machine remotely. Using same code
and I got error message as below
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `initialize'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:877:in `connect'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:851:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:582:in `start'
from /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/net/http.rb:506:in `post_form'
I found some solutions such as
setting a longer timeout for nethttp request
use some gmes like faraday, httpclient
But I don't know that they are some good solutions.
Besides, I guess it might be a server configuration issue.
So, I try to make sure production server is able to connect to the destination server.
sudo traceroute -w 1 -n -T IP
I got these, it seems well ?
traceroute to OOO.XXX.YYY (IP), 30 hops max, 60 byte packets
1 66.212.30.225 0.564 ms 0.599 ms 0.680 ms
2 96.44.180.41 66.869 ms 66.873 ms 67.103 ms
3 66.186.197.173 4.233 ms 4.248 ms 4.300 ms
4 206.223.143.104 0.656 ms 0.730 ms 0.798 ms
5 60.199.17.57 143.147 ms 143.135 ms 143.133 ms
6 60.199.18.157 143.067 ms 143.057 ms 143.020 ms
7 60.199.3.221 143.014 ms 142.997 ms 142.982 ms
8 60.199.3.142 142.994 ms 60.199.20.221 182.958 ms 60.199.23.14 143.085 ms
9 60.199.17.118 143.338 ms 60.199.17.114 143.199 ms 60.199.17.118 143.153 ms
10 219.80.114.86 145.561 ms 145.662 ms 145.608 ms
11 211.79.200.42 145.508 ms 145.517 ms 145.473 ms
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
Also, I sent mail to destination server make sure that I follow the post rule.
I try to do my best to fix this bug but....it still there~~

the problem is solved.....
The key point is destination server blocked IP from other country.
Therefore, I asked them setup whitelist for us then problem solved.

Related

Where clause on numbers dont give expected results

I have the following sample data in table_a.value:
abcdef 10 / 20 / 30 adfadsf
adfadsf 1000 / 10,5 / 300.5 kjbkjj
adsfadsf 0.1 / 8000 / 0,0005 asdfdasf
adsfasdf dfkjaf dsaflkjadslf asdfasdf 100 / 10.5 dslfjalksdf 500
adfdasf 50 sdlfkja 1000 alfdkjasf 50.5
ajkfdha asfdjlas dslkfjsdf
I want to filter out with a where clause row 1 to 3 where it has the following condition:
where table_a.value like '%number / number / number%'.
Expected results would be:
abcdef 10 / 20 / 30 adfadsf
adfadsf 1000 / 10,5 / 300.5 kjbkjj
adsfadsf 0.1 / 8000 / 0,0005 asdfdasf
I tried to make it work with the following code:
Where table_a.value like '%[0-9.,] / [0-9.,] / [0-9.,]%'
However, this is not giving me the expected results.
Could somebody guide me in the right direction?
SQL Server is not very good at doing this. You might be able to simplify your problem. For instance, you can get the same rows just by looking for two slashes surrounded by spaces:
where a_value like '% / % / %'
You can ensure that the central component is a number and that there are numbers before and after the spaces:
where a_value like '%[0-9] / [0-9]% / [0-9]%' and
a_value not like '%[0-9] / [0-9]%[^0-9]% / [0-9]%'
This is not 100% equivalent to what you want to do, but it might be sufficient for your purposes.
SQL Server does not expose any true regular expression functionality via TSQL. The pattern syntax does not have any sort of support for quantifiers.
In this case you could first use TRANSLATE to ensure that all characters in the set 0-9., are denoted as 0 and then use a couple of nested replaces to collapse down contiguous series of 0 to be represented as 12. (REPLACE(REPLACE(..., '0', '12'),'21',''))
The initial TRANSLATE ensures the input to that step can't have any other 1 or 2 characters.
Then check that the result is LIKE '%12 / 12 / 12%'
SELECT *
FROM ( VALUES ('abcdef 10 / 20 / 30 adfadsf'),
('adfadsf 1000 / 10,5 / 300.5 kjbkjj'),
('adsfadsf 0.1 / 8000 / 0,0005 asdfdasf'),
('adsfasdf dfkjaf dsaflkjadslf asdfasdf 100 / 10.5 dslfjalksdf 500'),
('adfdasf 50 sdlfkja 1000 alfdkjasf 50.5'),
('ajkfdha asfdjlas dslkfjsdf') )V(Col)
WHERE REPLACE(REPLACE(TRANSLATE(Col, '123456789.,', '00000000000'), '0', '12'), '21', '') LIKE '%12 / 12 / 12%'
(Fiddle)

How to insert selection between an interval in PostgreSQL?

I have a shapefile of airports. You can download it from here.
I've loaded this shapefile to postgreSQL. What I wanted is add points on centroids of each polygon.
1) I've added my point column;
select AddGeometryColumn('public','airport_shp','geom2',4326,'POINT',2);
2)Transformed coordinates from 3857 to 4326;
ALTER TABLE airport_shp ALTER COLUMN geom TYPE geometry(MultiPolygon,4326) USING ST_Transform(ST_SetSRID( geom,3857),4326);
3) I've inserted the centroids as points
insert into airport_shp(geom2) select st_centroid(geom) from airport_shp
The problem is; instead of adding the new values from the first empty row of the column, new values are added to the end of the file.
To make more sense below is representation of my first table;
*****************************************
* id *geom(MULTIPOLYGON)*geom2(POINT)*
*****************************************
* 1 *ADSADF23D31E475424* *
* 2 *2134ADSA0106000020* *
* 3 *214124RD74C5D6A5DE* *
* 4 *SAD23134230E24C5E4* *
*****************************************
I'm expecting this table to be like this after 3. step;
*****************************************
* id *geom(MULTIPOLYGON)*geom2(POINT)*
*****************************************
* 1 *ADSADF23D31E475424*ASDEF245A3RF*
* 2 *2134ADSA0106000020*523RFTYTFFTY*
* 3 *214124RD74C5D6A5DE*324FGSGSD523*
* 4 *SAD23134230E24C5E4*SADFS456V324*
*****************************************
But result is;
*****************************************
* id *geom(MULTIPOLYGON)*geom2(POINT)*
*****************************************
* 1 *ADSADF23D31E475424* *
* 2 *2134ADSA0106000020* *
* 3 *214124RD74C5D6A5DE* *
* 4 *SAD23134230E24C5E4* *
* 5 *ADSADF23D31E475424*ASDEF245A3RF*
* 6 *2134ADSA0106000020*523RFTYTFFTY*
* 7 *214124RD74C5D6A5DE*324FGSGSD523*
* 8 *SAD23134230E24C5E4*SADFS456V324*
*****************************************
Thanks in advance ! !
You need a UPDATE instead of INSERT:
UPDATE airport_shp SET geom2 = st_centroid(geom);

How can I correctly format "select top 1000 * from schema.table_name;" to work in Toad 4 Apache Hadoop?

Trying to run this in Toad 4 Apache Hadoop (Hive), and it does not recognize the top function. How can I reformat this?
select top 1000 * from Finance.ACCT_LIST
You can use LIMIT:
select * from Finance.ACCT_LIST
order by somecolumn
limit 1000
You should add an order by clause if you want to get a consistent set of rows.

SQL Server wrong mathematical result

I have this statement:
Select (30 - 5) * 700 / 30 as A , 700 - (5 * 700 / 30) as B
which has two ways to calculate the same equation.
These two equations should result in 583.33 if you made them by your calculator
but the previous statement results in 583 for field A, and 584 for field B.
Both are wrong and both are integer not decimal.
I want to know what's the right way to write this statement so I can get 583.33.
Thanks
Your expression is implicitly using an INT datatype. Try it this way to allow it to use a DECIMAL datatype
Select (30.000 - 5.000) * 700.000 / 30.000 as A ,
700.000 - (5.000 * 700.000 / 30.000) as B
Use Cast function:
As next:
Select Cast((30 - 5) * 700 as DECIMAL(19,2) ) / 30 as A ,
700 - ( Cast (5 * 700 as decimal (19,2 )) / 30) as B
Result:
A B
583.333333 583.333334

SQL in KDB or am I crazy?

I am trying to see if I can use KDB for some of my current work. I have a fair bit of code in legacy SQL and prospect of reuse seems exciting.
Which is when I came across: http://code.kx.com/q/interfaces/q-client-for-odbc/
This link only speaks of SQL select - is it OK to use this for insert and delete as well? What about performance?
Based on your question, I'm not sure this will do what you are hoping for. You seem to want to reuse SQL code on a non-SQL database.
This driver does not run SQL against the current database, it allows you to connect to an external database, and pull back data using the SQL capability of that other database. (ODBC is a standardised driver system for connecting to various kinds of databases, sending queries, and returning data).
This would only be useful if you intended to leave two different databases running side-by-side, and needed them to interact at the database level (rather than, as #millimoose mentions above, connecting to them individually from your application).
It is seldom used, but there is a way to use ANSI SQL with KDB. Just prefix the query with s)
q)t:([]col1:1 1 2 2;col2:10 10 20 20; col3:5.0 2.0 2.3 2.4; grp:aabc)
q)t
col1 col2 col3 grp`
------------------
1 10 5 a
1 10 2 a
2 20 2.3 b
2 20 2.4 c
q) /standard select
q)select from t
col1 col2 col3 grp
------------------`
1 10 5 a
1 10 2 a
2 20 2.3 b
2 20 2.4 c
q)/SQL type select with select *
q)select * from t
'rank
q) /Prefix the query with s)
q)s)select * from t
col1 col2 col3 grp
------------------
1 10 5 a
1 10 2 a
2 20 2.3 b
2 20 2.4 c
Now - this feature is rarely used and the parser is not optimized for this type of usage and resources are scarce. You'd probably spend more time debugging issues with this than you would just by converting your code to Q. Hope this helps.
Another option is to use the qodbc server -- http://code.kx.com/q/interfaces/q-server-for-odbc/