generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gabe
committed
Oct 21, 2023
1 parent
b3e4594
commit e5ff0b5
Showing
10 changed files
with
296 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dht | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-co-op/gocron" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Scheduler runs crob jobs asynchronously, designed to just schedule one job | ||
type Scheduler struct { | ||
scheduler *gocron.Scheduler | ||
job *gocron.Job | ||
} | ||
|
||
// NewScheduler creates a new scheduler | ||
func NewScheduler() Scheduler { | ||
s := gocron.NewScheduler(time.UTC) | ||
s.SingletonModeAll() | ||
return Scheduler{scheduler: s} | ||
} | ||
|
||
// Schedule schedules a job to run and starts it asynchronously | ||
func (s *Scheduler) Schedule(cron string, job func()) error { | ||
if s.job != nil { | ||
return errors.New("job already scheduled") | ||
} | ||
j, err := s.scheduler.Cron(cron).Do(job) | ||
if err != nil { | ||
return err | ||
} | ||
s.job = j | ||
s.Start() | ||
return nil | ||
} | ||
|
||
// Start starts the scheduler | ||
func (s *Scheduler) Start() { | ||
s.scheduler.StartAsync() | ||
} | ||
|
||
// Stop stops the scheduler | ||
func (s *Scheduler) Stop() { | ||
s.scheduler.Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,42 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TBD54566975/ssi-sdk/did" | ||
"github.com/TBD54566975/ssi-sdk/util" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/TBD54566975/did-dht-method/config" | ||
"github.com/TBD54566975/did-dht-method/pkg/storage" | ||
) | ||
|
||
// DIDService is the DID DHT service responsible for managing the DHT and reading/writing records | ||
type DIDService struct { | ||
cfg *config.Config | ||
db *storage.Storage | ||
pkarr PKARRService | ||
} | ||
|
||
// NewDIDService returns a new instance of the DHT service | ||
func NewDIDService(cfg *config.Config, db *storage.Storage, pkarr PKARRService) (*DIDService, error) { | ||
if cfg == nil { | ||
return nil, util.LoggingNewError("config is required") | ||
} | ||
if db == nil && !db.IsOpen() { | ||
return nil, util.LoggingNewError("storage is required be non-nil and to be open") | ||
} | ||
return &DIDService{ | ||
cfg: cfg, | ||
db: db, | ||
pkarr: pkarr, | ||
}, nil | ||
} | ||
|
||
type PublishDIDRequest struct { | ||
} | ||
|
||
func (s *DIDService) PublishDID(_ context.Context, _ PublishDIDRequest) error { | ||
return errors.New("unimplemented") | ||
} | ||
|
||
func (s *DIDService) GetDID(_ context.Context, did string) (*did.Document, error) { | ||
return nil, errors.New("unimplemented") | ||
} | ||
|
||
func (s *DIDService) ListDIDs(_ context.Context) ([]did.Document, error) { | ||
return nil, errors.New("unimplemented") | ||
} | ||
|
||
func (s *DIDService) DeleteDID(_ context.Context, _ string) error { | ||
return errors.New("unimplemented") | ||
} | ||
// // DIDService is the DID DHT service responsible for managing the DHT and reading/writing records | ||
// type DIDService struct { | ||
// cfg *config.Config | ||
// db *storage.Storage | ||
// pkarr PKARRService | ||
// } | ||
// | ||
// // NewDIDService returns a new instance of the DHT service | ||
// func NewDIDService(cfg *config.Config, db *storage.Storage, pkarr PKARRService) (*DIDService, error) { | ||
// if cfg == nil { | ||
// return nil, util.LoggingNewError("config is required") | ||
// } | ||
// if db == nil && !db.IsOpen() { | ||
// return nil, util.LoggingNewError("storage is required be non-nil and to be open") | ||
// } | ||
// return &DIDService{ | ||
// cfg: cfg, | ||
// db: db, | ||
// pkarr: pkarr, | ||
// }, nil | ||
// } | ||
// | ||
// type PublishDIDRequest struct { | ||
// } | ||
// | ||
// func (s *DIDService) PublishDID(_ context.Context, _ PublishDIDRequest) error { | ||
// return errors.New("unimplemented") | ||
// } | ||
// | ||
// func (s *DIDService) GetDID(_ context.Context, did string) (*did.Document, error) { | ||
// return nil, errors.New("unimplemented") | ||
// } | ||
// | ||
// func (s *DIDService) ListDIDs(_ context.Context) ([]did.Document, error) { | ||
// return nil, errors.New("unimplemented") | ||
// } | ||
// | ||
// func (s *DIDService) DeleteDID(_ context.Context, _ string) error { | ||
// return errors.New("unimplemented") | ||
// } |
Oops, something went wrong.