From 1f21fce9a38b5cf92fd41ea84c613b37e8734495 Mon Sep 17 00:00:00 2001 From: EkkoG Date: Mon, 29 Jan 2024 10:19:08 +0000 Subject: [PATCH 1/5] Add update subscription with cron job support --- .gitignore | 2 + cmd/run.go | 4 ++ db/subscription.go | 2 + go.mod | 5 +- go.sum | 20 +++++++ graphql/mutation.go | 1 + .../service/subscription/mutation_utils.go | 57 ++++++++++++++++++- graphql/service/subscription/resolver.go | 6 ++ graphql/service/subscription/schema.go | 2 + 9 files changed, 97 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 44b08f8..a71c1e9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ go-mod/ # log *.log + +__debug_bin* diff --git a/cmd/run.go b/cmd/run.go index d91fd3e..7dce577 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -19,6 +19,8 @@ import ( "github.com/daeuniverse/dae-wing/db" "github.com/daeuniverse/dae-wing/graphql" "github.com/daeuniverse/dae-wing/graphql/service/config" + + "github.com/daeuniverse/dae-wing/graphql/service/subscription" "github.com/daeuniverse/dae-wing/webrender" "github.com/golang-jwt/jwt/v5" "github.com/graph-gophers/graphql-go/relay" @@ -80,6 +82,8 @@ var ( logrus.Fatalln("Failed to init db:", err) } + subscription.UpdateAll(context.TODO()) + // Run dae. var logOpts *lumberjack.Logger if logFile != "" { diff --git a/db/subscription.go b/db/subscription.go index e245c42..fcab464 100644 --- a/db/subscription.go +++ b/db/subscription.go @@ -18,6 +18,8 @@ type Subscription struct { ID uint `gorm:"primaryKey;autoIncrement"` UpdatedAt time.Time `gorm:"not null"` Link string `gorm:"not null"` + CronExp string `gorm:"default:10 */6 * * *"` + CronEnable bool `gorm:"default:true"` Status string `gorm:"not null"` // Latency, error info, etc. Info string `gorm:"not null"` // Maybe include some info from provider diff --git a/go.mod b/go.mod index 220f193..f78d32d 100644 --- a/go.mod +++ b/go.mod @@ -47,10 +47,11 @@ require ( github.com/eknkc/basex v1.0.1 // indirect github.com/gaukas/godicttls v0.0.4 // indirect github.com/glebarez/go-sqlite v1.21.2 // indirect + github.com/go-co-op/gocron v1.37.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -72,6 +73,7 @@ require ( github.com/quic-go/quic-go v0.37.4 // indirect github.com/refraction-networking/utls v1.4.3 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/robfig/cron/v3 v3.0.1 // indirect github.com/safchain/ethtool v0.3.0 // indirect github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect github.com/spf13/pflag v1.0.5 // indirect @@ -81,6 +83,7 @@ require ( github.com/vishvananda/netns v0.0.4 // indirect github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect gitlab.com/yawning/chacha20.git v0.0.0-20230427033715-7877545b1b37 // indirect + go.uber.org/atomic v1.9.0 // indirect go.uber.org/mock v0.3.0 // indirect golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 // indirect golang.org/x/mod v0.12.0 // indirect diff --git a/go.sum b/go.sum index e2f82b5..b544a83 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,7 @@ github.com/bool64/dev v0.2.22/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8 github.com/cilium/ebpf v0.11.0 h1:V8gS/bTCCjX9uUnkUFUpPsksM8n1lXBAvHcpiFk1X2Y= github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUgWsVs= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d h1:hnC39MjR7xt5kZjrKlef7DXKFDkiX8MIcDXYC/6Jf9Q= github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d/go.mod h1:VGWGgv7pCP5WGyHGUyb9+nq/gW0yBm+i/GfCNATOJ1M= github.com/daeuniverse/outbound v0.0.0-20240101085641-7932e7df927d h1:hEZDwJvoTATxtNU8/kirJP9GK0tFxekXzT00cGXO0xg= @@ -47,6 +48,8 @@ github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9g github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= github.com/glebarez/sqlite v1.8.0 h1:02X12E2I/4C1n+v90yTqrjRa8yuo7c3KeHI3FRznCvc= github.com/glebarez/sqlite v1.8.0/go.mod h1:bpET16h1za2KOOMb8+jCp6UBP/iahDpfPQqSaYLTLx8= +github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0= +github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -68,6 +71,8 @@ github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+ github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v1.5.1-0.20230228210639-f05ace9f4a41 h1:9wDn2Cv3YJ57WZ5igOx6d2A5+j8DfChV0IlqINwZtoY= @@ -82,8 +87,13 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U= @@ -124,6 +134,7 @@ github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7 github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs= @@ -134,6 +145,10 @@ github.com/refraction-networking/utls v1.4.3 h1:BdWS3BSzCwWCFfMIXP3mjLAyQkdmog7d github.com/refraction-networking/utls v1.4.3/go.mod h1:4u9V/awOSBrRw6+federGmVJQfPtemEqLBXkML1b0bo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE= @@ -190,6 +205,8 @@ gitlab.com/yawning/chacha20.git v0.0.0-20230427033715-7877545b1b37 h1:ZrWBE3u/o9 gitlab.com/yawning/chacha20.git v0.0.0-20230427033715-7877545b1b37/go.mod h1:3x6b94nWCP/a2XB/joOPMiGYUBvqbLfeY/BkHLeDs6s= go.opentelemetry.io/otel v1.6.3/go.mod h1:7BgNga5fNlF/iZjG06hM3yofffp0ofKCDwSXx1GC4dI= go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= @@ -227,6 +244,9 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/graphql/mutation.go b/graphql/mutation.go index 35c749d..1ad5052 100644 --- a/graphql/mutation.go +++ b/graphql/mutation.go @@ -397,6 +397,7 @@ func (r *MutationResolver) ImportSubscription(args *struct { return nil, err } tx.Commit() + subscription.UpdateAll(context.Background()) return result, nil } diff --git a/graphql/service/subscription/mutation_utils.go b/graphql/service/subscription/mutation_utils.go index ebe2d7d..617de2f 100644 --- a/graphql/service/subscription/mutation_utils.go +++ b/graphql/service/subscription/mutation_utils.go @@ -19,6 +19,7 @@ import ( "github.com/daeuniverse/dae-wing/graphql/internal" "github.com/daeuniverse/dae-wing/graphql/service/node" "github.com/daeuniverse/dae/common/subscription" + "github.com/go-co-op/gocron" "github.com/graph-gophers/graphql-go" "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -168,11 +169,61 @@ func AutoUpdateVersionByIds(d *gorm.DB, ids []uint) (err error) { return nil } +var schedulerCache = make(map[uint]*gocron.Scheduler) + +func UpdateAll(ctx context.Context) { + + var subs []db.Subscription + if err := db.DB(ctx).Find(&subs).Error; err != nil { + logrus.Error(err) + return + } + for _, sub := range subs { + AddUpdateScheduler(ctx, sub.ID) + } +} + +func AddUpdateScheduler(ctc context.Context, id uint) { + var sub db.Subscription + if err := db.DB(ctc).Where("id = ?", id).First(&sub).Error; err != nil { + logrus.Error(err) + return + } + if sub.CronEnable && schedulerCache[sub.ID] == nil { + s := gocron.NewScheduler(time.Local) + logrus.Info("Subscription " + *sub.Tag + " update task enabled, with exp " + sub.CronExp) + s.Cron(sub.CronExp).Do(func() { + if _, err := UpdateById(ctc, sub.ID); err != nil { + logrus.Error(err) + } + }) + s.StartAsync() + schedulerCache[sub.ID] = s + } +} + +func RemoveUpdateScheduler(id uint) { + if schedulerCache[id] != nil { + logrus.Info("Subscription " + string(id) + " update task disabled") + schedulerCache[id].Stop() + delete(schedulerCache, id) + } +} + func Update(ctx context.Context, _id graphql.ID) (r *Resolver, err error) { subId, err := common.DecodeCursor(_id) if err != nil { return nil, err } + var m *db.Subscription + m, err = UpdateById(ctx, subId) + if err != nil { + return nil, err + } + return &Resolver{Subscription: m}, nil +} + +func UpdateById(ctx context.Context, subId uint) (sub *db.Subscription, err error) { // Fetch node links. var m db.Subscription if err = db.DB(ctx).Where(&db.Subscription{ID: subId}).First(&m).Error; err != nil { @@ -234,7 +285,7 @@ func Update(ctx context.Context, _id graphql.ID) (r *Resolver, err error) { if err = AutoUpdateVersionByIds(tx, []uint{subId}); err != nil { return nil, err } - return &Resolver{Subscription: &m}, nil + return &m, nil } func Remove(ctx context.Context, _ids []graphql.ID) (n int32, err error) { @@ -280,6 +331,10 @@ func Remove(ctx context.Context, _ids []graphql.ID) (n int32, err error) { return 0, q.Error } + for _, id := range ids { + RemoveUpdateScheduler(id) + } + return int32(q.RowsAffected), nil } diff --git a/graphql/service/subscription/resolver.go b/graphql/service/subscription/resolver.go index fe0ee26..6464449 100644 --- a/graphql/service/subscription/resolver.go +++ b/graphql/service/subscription/resolver.go @@ -30,6 +30,12 @@ func (r *Resolver) Tag() *string { func (r *Resolver) Link() string { return r.Subscription.Link } +func (r *Resolver) CronExp() string { + return r.Subscription.CronExp +} +func (r *Resolver) CronEnable() bool { + return r.Subscription.CronEnable +} func (r *Resolver) Status() string { return r.Subscription.Status } diff --git a/graphql/service/subscription/schema.go b/graphql/service/subscription/schema.go index fdb45e2..833f690 100644 --- a/graphql/service/subscription/schema.go +++ b/graphql/service/subscription/schema.go @@ -12,6 +12,8 @@ type Subscription { updatedAt: Time! tag: String link: String! + cronExp: String! + cronEnable: Boolean! status: String! info: String! nodes(first: Int, after: ID): NodesConnection! From ad4978151f68425f614ee2a1f06ba856ec25a807 Mon Sep 17 00:00:00 2001 From: Ekko Date: Mon, 29 Jan 2024 18:58:55 +0800 Subject: [PATCH 2/5] Update db/subscription.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sumire (菫) <151038614+sumire88@users.noreply.github.com> --- db/subscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/subscription.go b/db/subscription.go index fcab464..aba90a2 100644 --- a/db/subscription.go +++ b/db/subscription.go @@ -19,7 +19,7 @@ type Subscription struct { UpdatedAt time.Time `gorm:"not null"` Link string `gorm:"not null"` CronExp string `gorm:"default:10 */6 * * *"` - CronEnable bool `gorm:"default:true"` + CronEnable bool `gorm:"default:true"` Status string `gorm:"not null"` // Latency, error info, etc. Info string `gorm:"not null"` // Maybe include some info from provider From fee53ddd401fbfd27053efa14514f1d6bfa7f090 Mon Sep 17 00:00:00 2001 From: Ekko Date: Mon, 29 Jan 2024 18:58:55 +0800 Subject: [PATCH 3/5] Update db/subscription.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sumire (菫) <151038614+sumire88@users.noreply.github.com> --- db/subscription.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/db/subscription.go b/db/subscription.go index aba90a2..a896781 100644 --- a/db/subscription.go +++ b/db/subscription.go @@ -15,13 +15,13 @@ var ( ) type Subscription struct { - ID uint `gorm:"primaryKey;autoIncrement"` - UpdatedAt time.Time `gorm:"not null"` - Link string `gorm:"not null"` - CronExp string `gorm:"default:10 */6 * * *"` - CronEnable bool `gorm:"default:true"` - Status string `gorm:"not null"` // Latency, error info, etc. - Info string `gorm:"not null"` // Maybe include some info from provider + ID uint `gorm:"primaryKey;autoIncrement"` + UpdatedAt time.Time `gorm:"not null"` + Link string `gorm:"not null"` + CronExp string `gorm:"default:10 */6 * * *"` + CronEnable bool `gorm:"default:true"` + Status string `gorm:"not null"` // Latency, error info, etc. + Info string `gorm:"not null"` // Maybe include some info from provider Tag *string `gorm:"unique"` From f26f0df7200ff5d1af893f0ece93e7e6376f81d0 Mon Sep 17 00:00:00 2001 From: Ekko Date: Mon, 29 Jan 2024 18:58:55 +0800 Subject: [PATCH 4/5] Update db/subscription.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sumire (菫) <151038614+sumire88@users.noreply.github.com> --- graphql/mutation.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphql/mutation.go b/graphql/mutation.go index 1ad5052..670d41d 100644 --- a/graphql/mutation.go +++ b/graphql/mutation.go @@ -12,6 +12,7 @@ import ( "fmt" "io" "strings" + "time" "unicode" "github.com/daeuniverse/dae-wing/db" @@ -397,7 +398,9 @@ func (r *MutationResolver) ImportSubscription(args *struct { return nil, err } tx.Commit() - subscription.UpdateAll(context.Background()) + ctx, caceel := context.WithTimeout(context.Background(), 10 * time.Second) + subscription.UpdateAll(ctx) + defer caceel() return result, nil } From 1a7cb97570346b22b90c8b398f063a2a224a20ea Mon Sep 17 00:00:00 2001 From: EkkoG Date: Sat, 1 Jun 2024 13:20:27 +0000 Subject: [PATCH 5/5] chore: format code --- graphql/mutation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/mutation.go b/graphql/mutation.go index 670d41d..22d76be 100644 --- a/graphql/mutation.go +++ b/graphql/mutation.go @@ -398,7 +398,7 @@ func (r *MutationResolver) ImportSubscription(args *struct { return nil, err } tx.Commit() - ctx, caceel := context.WithTimeout(context.Background(), 10 * time.Second) + ctx, caceel := context.WithTimeout(context.Background(), 10*time.Second) subscription.UpdateAll(ctx) defer caceel() return result, nil