-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.go
62 lines (50 loc) · 1.78 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"github.com/noting59/Golang-Solid-Implementation/infrastructures"
"github.com/noting59/Golang-Solid-Implementation/repositories"
"github.com/noting59/Golang-Solid-Implementation/services"
"log"
"time"
)
func init() {
config := infrastructures.Config{}
db, err := sql.Open("postgres", config.GetConf().PostgreSQLConn)
if err != nil {
log.Fatal(err)
}
postgreSQLHandler = &infrastructures.PostgreSQLHandler{}
postgreSQLHandler.Conn = db
orderRepository = &repositories.OrderRepository{IDbHandler: postgreSQLHandler}
userRepository = &repositories.UserRepository{IDbHandler: postgreSQLHandler}
productRepository = &repositories.ProductRepository{IDbHandler: postgreSQLHandler}
cartRepository = &repositories.CartRepository{IDbHandler: postgreSQLHandler}
userService = &services.UserService{IUserRepository: userRepository}
productService = &services.ProductService{IProductRepository: productRepository, ICartRepository: cartRepository}
cartService = &services.CartService{ICartRepository: cartRepository, IProductService: productService, IUserService: userService}
orderService = &services.OrderService{IOrderRepository: orderRepository, IProductService: productService, IUserService: userService}
paymentService = &infrastructures.SolidPayments{
IOrderService: orderService,
ICartService: cartService,
IUserService: userService,
}
}
func DoEvery(d time.Duration) {
for _ = range time.Tick(d) {
Task()
}
}
// Spider scans website's market.
func Task() {
list := orderService.GetUnProcessedOrders("processing")
log.Print(list)
for _, elem := range list {
_, err := paymentService.StatusCheck(elem.Id)
if err != nil {
log.Print(err)
}
log.Print(fmt.Sprintf("Order %d processed", elem.Id))
}
}