o Obj
и lp string
указанные в качестве аргумента?! CREATE PROCEDURE tracker(CUSTOM_TIME VARCHAR) AS $FUNCTION$
BEGIN
UPDATE SURVEYS SET CONDITION = 3 WHERE BLOCKED AND CONDITION = 2 AND CUSTOM_TIME > END_PERIOD;
UPDATE SURVEYS SET BLOCKED = TRUE WHERE NOT BLOCKED AND CONDITION = 2 AND CUSTOM_TIME BETWEEN START_PERIOD AND END_PERIOD;
END;
$FUNCTION$ LANGUAGE plpgsql;
CALL tracker('2019-03-29 16:37:00');
SQL Error [42883]: ERROR: operator does not exist: character varying > timestamp without time zone
Подсказка: No operator matches the given name and argument types. You might need to add explicit type casts.
Где: PL/pgSQL function tracker(character varying) line 3 at SQL statement
pq: sorry, too many clients already
. Предпологается что в таблице с которой работаю сейчас будет всегда 200-300 записей. На стороне БД увеличил количество коннекшенов на 500. Сейчас при 200 запросов на update warning-ов не возникает.var Tracker = func() {
// Инициализируем массив.
var products [] models.Product
// Получаем список продуктов из базы данных.
if err := db.Find(&products).Error; err != nil {
log.Fatal(err)
return
}
// Создаем канал.
channel := make(chan models.Product, len(products))
// Запускаю 5 воркеров.
for w := 1; w <= 5; w++ {
go Worker(worker, channel, currentTime)
}
// Устанавливаю емкость канала.
for j := 1; j <= len(products); j++ {
channel <- surveys[i]
}
close(channel)
}
func Worker(workerID int, channel <- chan models.BetaSurvey, currentTime time.Time) {
fmt.Println("worker", workerID, "started job")
for product := range channel {
startPeriod := product.StartPeriod.UTC()
endPeriod := product.EndPeriod.UTC()
if product.Blocked == false {
if startPeriod.Before(currentTime) && endPeriod.After(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("blocked", true).Error; err != nil {
log.Println(err)
return
}
}
} else if product.Blocked == true {
if endPeriod.Before(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("condition", 3).Error; err != nil {
log.Println(err)
return
}
}
}
}
fmt.Println("worker", workerID, "finished job")
}
var Tracker = func() {
// Инициализируем массив.
var products [] models.Product
// Получаем список продуктов из базы данных.
if err := db.Find(&products).Error; err != nil {
log.Fatal(err)
return
}
// Создаем канал.
channel := make(chan models.Product, len(products))
// Запускаю 5 воркеров.
for w := 1; w <= 5; w++ {
go worker(w, channel)
}
// Устанавливаю емкость канала.
for j := 1; j <= 10; j++ {
channel <- j
}
close(channel)
}
func Worker(id int, channel <- chan models.Product) {
for product := range channel {
// Остальной код
}
}
***
currentTime := time.Now().In(timezone).UTC().Add(6 * time.Hour)
for _, product := range products {
go Checker(product, currentTime)
}
***
func Checker(product models.Product, currentTime time.Time) {
startPeriod := product.StartPeriod.UTC()
endPeriod := product.EndPeriod.UTC()
if product.Blocked == false {
if startPeriod.Before(currentTime) && endPeriod.After(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("blocked", true).Error; err != nil {
log.Println(err)
return
}
}
} else if product.Blocked == true {
if endPeriod.Before(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("condition", 3).Error; err != nil {
log.Println(err)
return
}
}
}
}
pq: sorry, too many clients already
. Это случаем не из-за тех самых транзакций о которых вы говорите? При этом в базе все изменилось, правда не все сразу а как-то по частям, некоторые с опозданием на секунду. Аномалий не заметил других. Сколько в теории горутины можно создать? Это зависит от машины, я прав?***
currentTime := time.Now().In(timezone).UTC().Add(6 * time.Hour)
for _, product := range products {
go Checker(product, currentTime)
}
***
func Checker(product models.Product, currentTime time.Time) {
startPeriod := product.StartPeriod.UTC()
endPeriod := product.EndPeriod.UTC()
if product.Blocked == false {
if startPeriod.Before(currentTime) && endPeriod.After(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("blocked", true).Error; err != nil {
log.Println(err)
return
}
}
} else if product.Blocked == true {
if endPeriod.Before(currentTime) {
if err := database.DBGORM.Find(&product).Error; err != nil {
log.Println(err)
return
}
if err := database.DBGORM.Model(&product).Update("condition", 3).Error; err != nil {
log.Println(err)
return
}
}
}
}
pq: sorry, too many clients already
. При этом в базе все изменилось, чуть чуть с опозданием. Сколько в теории горутины можно создать? Это зависит от машины, я прав? sql: expected 3 arguments, got 1
. Получается в этом выражении .Query(stmt, args)
args это массив. Нужно сюда каждый элемент массива через запятую вставить. Я правильно понимаю? Могли бы пожалуйста что-нибудь посоветовать? :1, :2, :3
почему-то не работает..Query("SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORGWHERE ORGANIZATION_ID IN (:value1, :value2, :value3)", "27625", "27626", "27627")
.Query("SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value1, :value2, :value3)", "27625", "27626", "27627")
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value,:value,:value)
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value1,:value2,:value3)
sql: expected 1 arguments, got 3
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value,:value,:value)
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value1,:value2,:value3)
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value,:value,:value)
SELECT ORGANIZATION_ID, ORGANIZATION_NAME FROM ORG WHERE ORGANIZATION_ID IN (:value1,:value2,:value3)
User 'mysql_user' has exceeded the 'max_user_connections' resource (current value: 20)
set global max_connections = 200;
к примеру. Данное решение скорее всего решит проблему лишь временно и через некоторое время проблема повторится.docker pull karalabe/xgo-latest
xgo -targets linux/amd64 .
Выдал такой message:Checking docker installation...
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24302
Built: Fri Mar 23 08:31:36 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server: Docker Engine - Community
Engine:
Version: 18.09.3
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb 28 06:40:51 2019
OS/Arch: linux/amd64
Experimental: false
Checking for required docker image karalabe/xgo-latest... found.
Cross compiling application...
docker: Error response from daemon: invalid mode: /build.
See 'docker run --help'.
2019/03/12 21:09:13 Failed to cross compile package: exit status 125.
main.go:9:2: cannot find package "application/database" in any of:
/go/src/application/vendor/application/database (vendor tree)
/usr/local/go/src/application/database (from $GOROOT)
/go/src/application/database (from $GOPATH)
main.go:10:2: cannot find package "application/routes" in any of:
/go/src/application/vendor/application/routes (vendor tree)
/usr/local/go/src/application/routes (from $GOROOT)
/go/src/application/routes (from $GOPATH)
main.go:11:2: cannot find package "application/utils" in any of:
/go/src/application/vendor/application/utils (vendor tree)
/usr/local/go/src/application/utils (from $GOROOT)
/go/src/application/utils (from $GOPATH)
controllers/factor.go:10:2: cannot find package "application/models" in any of:
/go/src/application/vendor/application/models (vendor tree)
/usr/local/go/src/application/models (from $GOROOT)
/go/src/application/models (from $GOPATH)
vendor/gopkg.in/goracle.v2/conn.go:33:2: cannot find package "github.com/pkg/errors" in any of:
/go/src/application/vendor/github.com/pkg/errors (vendor tree)
/usr/local/go/src/github.com/pkg/errors (from $GOROOT)
/go/src/github.com/pkg/errors (from $GOPATH)
routes/routes.go:5:2: cannot find package "application/controllers" in any of:
/go/src/application/vendor/application/controllers (vendor tree)
/usr/local/go/src/application/controllers (from $GOROOT)
/go/src/application/controllers (from $GOPATH)
drwxr-xr-x. 10 root root 222 Mar 12 14:07 .
drwxrwxrwx. 4 root root 43 Mar 12 14:07 ..
-rw-r--r--. 1 root root 326 Mar 7 11:18 .env
drwxr-xr-x. 7 root root 150 Mar 12 09:16 .git
-rw-r--r--. 1 root root 12 Mar 3 15:09 .gitignore
drwxr-xr-x. 4 root root 192 Mar 12 09:16 .idea
-rw-r--r--. 1 root root 804 Mar 12 2019 Dockerfile
-rw-r--r--. 1 root root 2603 Mar 12 05:14 README.md
drwxr-xr-x. 2 root root 173 Mar 12 09:16 controllers
drwxr-xr-x. 2 root root 44 Mar 12 09:16 database
-rw-r--r--. 1 root root 1951 Mar 7 11:32 main.go
drwxr-xr-x. 2 root root 93 Mar 12 09:16 models
-rw-r--r--. 1 root root 16507975 Mar 12 08:47 application
drwxr-xr-x. 2 root root 23 Mar 12 09:16 routes
drwxr-xr-x. 2 root root 22 Mar 12 09:16 utils
drwxr-xr-x. 3 root root 22 Mar 12 09:16 vendor
Step 11/13 : RUN go build -o /application .
---> Running in 98a045250847
main.go:9:2: cannot find package "application/database" in any of:
/go/src/application/vendor/application/database (vendor tree)
/usr/local/go/src/application/database (from $GOROOT)
/go/src/application/database (from $GOPATH)
main.go:10:2: cannot find package "application/routes" in any of:
/go/src/application/vendor/application/routes (vendor tree)
/usr/local/go/src/application/routes (from $GOROOT)
/go/src/application/routes (from $GOPATH)
main.go:11:2: cannot find package "application/utils" in any of:
/go/src/application/vendor/application/utils (vendor tree)
/usr/local/go/src/application/utils (from $GOROOT)
/go/src/application/utils (from $GOPATH)
Пытаюсь объединить два пункта в одну процедуру, как вы и советовали. Я написал такую процедуру:
Вызываю эту процедуру следующим образом:
При вызове происходит ошибка:
Где в процедуре я ошибся?