MCPcopy Create free account
hub / github.com/remotemobprogramming/mob / startBreakTimer

Function startBreakTimer

timer.go:95–137  ·  view source on GitHub ↗
(timerInMinutes string, configuration config.Configuration)

Source from the content-addressed store, hash-verified

93}
94
95func startBreakTimer(timerInMinutes string, configuration config.Configuration) error {
96 err, timeoutInMinutes := toMinutes(timerInMinutes)
97 if err != nil {
98 return err
99 }
100
101 timeoutInSeconds := timeoutInMinutes * 60
102 timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04")
103 say.Debug(fmt.Sprintf("Starting break timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes))
104
105 room := getMobTimerRoom(configuration)
106 startRemoteTimer := room != ""
107 startLocalTimer := configuration.TimerLocal
108
109 if !startRemoteTimer && !startLocalTimer {
110 say.Error("No break timer configured, not starting break timer")
111 Exit(1)
112 }
113
114 if startRemoteTimer {
115 timerUser := getUserForMobTimer(configuration.TimerUser)
116 err := httpPutBreakTimer(timeoutInMinutes, room, timerUser, configuration.TimerUrl, configuration.TimerInsecure)
117
118 if err != nil {
119 say.Error("remote break timer couldn't be started")
120 say.Error(err.Error())
121 Exit(1)
122 }
123 }
124
125 if startLocalTimer {
126 err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand("mob start", configuration.VoiceCommand), getNotifyCommand("mob start", configuration.NotifyCommand), "echo \"mobTimer\"")
127
128 if err != nil {
129 say.Error(fmt.Sprintf("break timer couldn't be started on your system (%s)", runtime.GOOS))
130 say.Error(err.Error())
131 Exit(1)
132 }
133 }
134
135 say.Info("It's now " + currentTime() + ". " + fmt.Sprintf("%d min break timer ends at approx. %s", timeoutInMinutes, timeOfTimeout) + ". So take a break now! :)")
136 return nil
137}
138
139func getUserForMobTimer(userOverride string) string {
140 if userOverride == "" {

Callers 4

TestBreakTimerNotANumberFunction · 0.85
TestBreakTimerFunction · 0.85
StartBreakTimerFunction · 0.85

Calls 12

DebugFunction · 0.92
ErrorFunction · 0.92
InfoFunction · 0.92
toMinutesFunction · 0.85
getMobTimerRoomFunction · 0.85
getUserForMobTimerFunction · 0.85
httpPutBreakTimerFunction · 0.85
getSleepCommandFunction · 0.85
getVoiceCommandFunction · 0.85
getNotifyCommandFunction · 0.85
currentTimeFunction · 0.85

Tested by 3

TestBreakTimerNotANumberFunction · 0.68
TestBreakTimerFunction · 0.68