Skip to content

Commit

Permalink
Clean "update-interval" from daemon subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
naspeh committed Apr 25, 2024
1 parent daa53a3 commit dc6988e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
1 change: 0 additions & 1 deletion testcmd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
timefor daemon [command options]
OPTIONS:
--update-interval value interval to update activity time in db (default: 30s)
--break-interval value interval to show a break reminder (default: 1h20m0s)
--repeat-interval value interval to repeat a break reminder (default: 10m0s)
--hook value a hook command template
Expand Down
4 changes: 2 additions & 2 deletions timefor
Git LFS file not shown
12 changes: 2 additions & 10 deletions timefor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

const (
intervalToExpire = 10 * time.Minute
defaultIntervalToUpdateDb = 30 * time.Second
defaultIntervalToShowBreakReminder = 80 * time.Minute
defaultIntervalToRepeatBreakReminder = 10 * time.Minute
defaultTpl = "{{if .Active}}☭{{else}}☯{{end}} {{.FormatLabel}}"
Expand Down Expand Up @@ -221,11 +220,6 @@ func newCmd(db *sqlx.DB) error {
Usage: "Update the duration for current activity and run hook if specified",
ArgsUsage: " ",
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "update-interval",
Usage: "interval to update activity time in db",
Value: defaultIntervalToUpdateDb,
},
&cli.DurationFlag{
Name: "break-interval",
Usage: "interval to show a break reminder",
Expand All @@ -246,12 +240,11 @@ func newCmd(db *sqlx.DB) error {
return cli.ShowSubcommandHelp(cCtx)
}

intervalToUpdateDb := cCtx.Duration("update-interval")
intervalToShowBreakReminder := cCtx.Duration("break-interval")
intervalToRepeatBreakReminder := cCtx.Duration("repeat-interval")
hook := cCtx.String("hook")

err := Daemon(db, intervalToUpdateDb, intervalToShowBreakReminder, intervalToRepeatBreakReminder, hook)
err := Daemon(db, intervalToShowBreakReminder, intervalToRepeatBreakReminder, hook)
if err != nil {
return err
}
Expand Down Expand Up @@ -488,7 +481,6 @@ func Show(db *sqlx.DB, tpl string) error {
// Daemon updates the duration of current activity and runs the hook if specified
func Daemon(
db *sqlx.DB,
intervalToUpdateDb time.Duration,
intervalToShowBreakReminder time.Duration,
intervalToRepeatBreakReminder time.Duration,
hook string,
Expand Down Expand Up @@ -550,7 +542,7 @@ func Daemon(
log.Println("change", c)

case <-time.After(nextUpdate):
if activity.Active() && time.Since(activity.Updated()) > intervalToUpdateDb {
if activity.Active() && time.Since(activity.Updated()) > time.Minute {
fmt.Printf("updating time for %s\n", activity.Name)
_, err := UpdateIfExists(db, "", false)
if err != nil {
Expand Down

0 comments on commit dc6988e

Please sign in to comment.