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.
* republishing and storage * fix republishing * Testing * server tests * readme for the impl * fix tests
- Loading branch information
1 parent
f7466b4
commit f93a1e2
Showing
23 changed files
with
641 additions
and
285 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Server Implementation | ||
|
||
- Heavily a work-in-progress | ||
- Designed to be run as a single instance | ||
|
||
## Config | ||
|
||
# TOML Config File | ||
|
||
Config is managed using a [TOML](https://toml.io/en/) [file](../../config/dev.toml). There are sets of configuration values for the server | ||
(e.g. which port to listen on), the services (e.g. which database to use), and each service. | ||
|
||
Each service may define specific configuration, such as which DID methods are enabled for the DID service. | ||
|
||
A full config example is [provided here](../../config/kitchensink.toml). | ||
|
||
## Usage | ||
|
||
How it works: | ||
|
||
1. On startup the service loads default values into the `ServiceConfig` | ||
2. Checks for a TOML config file: | ||
- If exists, load toml file | ||
- If does not exist, it uses a default config defined in the code inline | ||
3. Loads the `config/.env` file and adds the env variables defined in this file to the final `ServiceConfig` | ||
|
||
## Build & Run | ||
|
||
Run: | ||
|
||
``` | ||
docker build . -t did-dht -f build/Dockerfile | ||
``` | ||
|
||
and then | ||
|
||
``` | ||
docker run -p8305:8305 did-dht | ||
``` | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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(_ string, job func()) error { | ||
if s.job != nil { | ||
return errors.New("job already scheduled") | ||
} | ||
j, err := s.scheduler.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
Oops, something went wrong.