mirror of
https://github.com/crazy-max/diun.git
synced 2025-03-16 04:13:30 +00:00
Use zoneinfo from Go (#202)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
cf0b5c01e2
commit
67071ea11f
10 changed files with 19 additions and 24 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -4,7 +4,6 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- '**'
|
||||
- 'v*'
|
||||
tags:
|
||||
- 'v*'
|
||||
paths-ignore:
|
||||
|
@ -23,7 +22,6 @@ on:
|
|||
- 'mkdocs.yml'
|
||||
|
||||
jobs:
|
||||
|
||||
go:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
|
|
@ -31,7 +31,6 @@ LABEL maintainer="CrazyMax"
|
|||
RUN apk --update --no-cache add \
|
||||
ca-certificates \
|
||||
libressl \
|
||||
tzdata \
|
||||
&& rm -rf /tmp/* /var/cache/apk/*
|
||||
|
||||
COPY --from=builder /app/diun /usr/local/bin/diun
|
||||
|
|
11
cmd/main.go
11
cmd/main.go
|
@ -7,7 +7,6 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/crazy-max/diun/v4/internal/app"
|
||||
|
@ -54,14 +53,8 @@ func main() {
|
|||
Summary: true,
|
||||
}))
|
||||
|
||||
// Load timezone location
|
||||
location, err := time.LoadLocation(cli.Timezone)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msgf("Cannot load timezone %s", cli.Timezone)
|
||||
}
|
||||
|
||||
// Init
|
||||
logging.Configure(&cli, location)
|
||||
logging.Configure(&cli)
|
||||
log.Info().Str("version", version).Msgf("Starting %s", meta.Name)
|
||||
|
||||
// Handle os signals
|
||||
|
@ -82,7 +75,7 @@ func main() {
|
|||
log.Debug().Msg(cfg.String())
|
||||
|
||||
// Init
|
||||
if diun, err = app.New(meta, cli, cfg, location); err != nil {
|
||||
if diun, err = app.New(meta, cli, cfg); err != nil {
|
||||
log.Fatal().Err(err).Msgf("Cannot initialize %s", meta.Name)
|
||||
}
|
||||
|
||||
|
|
12
docs/faq.md
12
docs/faq.md
|
@ -1,5 +1,17 @@
|
|||
# FAQ
|
||||
|
||||
## Timezone
|
||||
|
||||
By default, all interpretation and scheduling is done with your local timezone (`TZ` environment variable).
|
||||
|
||||
Cron schedule may also override the timezone to be interpreted in by providing an additional space-separated field
|
||||
at the beginning of the cron spec, of the form `CRON_TZ=<timezone>`:
|
||||
|
||||
```yaml
|
||||
watch:
|
||||
schedule: "CRON_TZ=Asia/Tokyo 0 */6 * * *"
|
||||
```
|
||||
|
||||
## Test notifications
|
||||
|
||||
Through the [command line](usage/cli.md) with:
|
||||
|
|
|
@ -36,7 +36,6 @@ and [File](providers/file.md) providers available
|
|||
* Get notified through Gotify, Mail, Slack, Telegram and [more](config/index.md#reference)
|
||||
* [Healthchecks support](config/watch.md#healthchecks) to monitor Diun watcher
|
||||
* Enhanced logging
|
||||
* Timezone can be changed
|
||||
* Official [Docker image available](install/docker.md)
|
||||
|
||||
## License
|
||||
|
|
|
@ -21,6 +21,7 @@ User=diun
|
|||
Group=diun
|
||||
ExecStart=/usr/local/bin/diun --config /etc/diun/diun.yml --log-level info
|
||||
Restart=always
|
||||
#Environment=TZ=Europe/Paris
|
||||
Environment=DIUN_DB_PATH=/var/lib/diun/diun.db
|
||||
|
||||
[Install]
|
||||
|
|
|
@ -18,7 +18,6 @@ Flags:
|
|||
--help Show context-sensitive help.
|
||||
--version
|
||||
--config=STRING Diun configuration file ($CONFIG).
|
||||
--timezone="UTC" Timezone assigned to Diun ($TZ).
|
||||
--log-level="info" Set log level ($LOG_LEVEL).
|
||||
--log-json Enable JSON logging output ($LOG_JSON).
|
||||
--log-caller Add file:line of the caller to log output ($LOG_CALLER).
|
||||
|
@ -32,7 +31,6 @@ Following environment variables can be used in place:
|
|||
| Name | Default | Description |
|
||||
|--------------------|---------------|---------------|
|
||||
| `CONFIG` | | Diun configuration file |
|
||||
| `TZ` | `UTC` | Timezone assigned |
|
||||
| `LOG_LEVEL` | `info` | Log level output |
|
||||
| `LOG_JSON` | `false` | Enable JSON logging output |
|
||||
| `LOG_CALLER` | `false` | Enable to add `file:line` of the caller |
|
||||
|
|
|
@ -39,14 +39,14 @@ type Diun struct {
|
|||
}
|
||||
|
||||
// New creates new diun instance
|
||||
func New(meta model.Meta, cli model.Cli, cfg *config.Config, location *time.Location) (*Diun, error) {
|
||||
func New(meta model.Meta, cli model.Cli, cfg *config.Config) (*Diun, error) {
|
||||
var err error
|
||||
|
||||
diun := &Diun{
|
||||
meta: meta,
|
||||
cfg: cfg,
|
||||
cron: cron.New(cron.WithLocation(location), cron.WithParser(cron.NewParser(
|
||||
cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor),
|
||||
cron: cron.New(cron.WithParser(cron.NewParser(
|
||||
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor),
|
||||
)),
|
||||
}
|
||||
|
||||
|
|
|
@ -13,14 +13,10 @@ import (
|
|||
)
|
||||
|
||||
// Configure configures logger
|
||||
func Configure(cli *model.Cli, location *time.Location) {
|
||||
func Configure(cli *model.Cli) {
|
||||
var err error
|
||||
var w io.Writer
|
||||
|
||||
zerolog.TimestampFunc = func() time.Time {
|
||||
return time.Now().In(location)
|
||||
}
|
||||
|
||||
if !cli.LogJSON {
|
||||
w = zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
|
|
|
@ -6,7 +6,6 @@ import "github.com/alecthomas/kong"
|
|||
type Cli struct {
|
||||
Version kong.VersionFlag
|
||||
Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"`
|
||||
Timezone string `kong:"name='timezone',env='TZ',default='UTC',help='Timezone assigned to Diun.'"`
|
||||
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
|
||||
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
|
||||
LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"`
|
||||
|
|
Loading…
Reference in a new issue