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

Function startTimer

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

Source from the content-addressed store, hash-verified

19}
20
21func startTimer(timerInMinutes string, configuration config.Configuration) error {
22 err, timeoutInMinutes := toMinutes(timerInMinutes)
23 if err != nil {
24 return err
25 }
26
27 timeoutInSeconds := timeoutInMinutes * 60
28 timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04")
29 say.Debug(fmt.Sprintf("Starting timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes))
30
31 room := getMobTimerRoom(configuration)
32 startRemoteTimer := room != ""
33 startLocalTimer := configuration.TimerLocal
34
35 if !startRemoteTimer && !startLocalTimer {
36 say.Error("No timer configured, not starting timer")
37 Exit(1)
38 }
39
40 if startRemoteTimer {
41 timerUser := getUserForMobTimer(configuration.TimerUser)
42 err := httpPutTimer(timeoutInMinutes, room, timerUser, configuration.TimerUrl, configuration.TimerInsecure)
43 if err != nil {
44 say.Error("remote timer couldn't be started")
45 say.Error(err.Error())
46 Exit(1)
47 }
48 }
49
50 if startLocalTimer {
51 err := executeCommandsInBackgroundProcess(getSleepCommand(timeoutInSeconds), getVoiceCommand(configuration.VoiceMessage, configuration.VoiceCommand), getNotifyCommand(configuration.NotifyMessage, configuration.NotifyCommand), "echo \"mobTimer\"")
52
53 if err != nil {
54 say.Error(fmt.Sprintf("timer couldn't be started on your system (%s)", runtime.GOOS))
55 say.Error(err.Error())
56 Exit(1)
57 }
58 }
59
60 say.Info("It's now " + currentTime() + ". " + fmt.Sprintf("%d min timer ends at approx. %s", timeoutInMinutes, timeOfTimeout) + ". Happy collaborating! :)")
61 return nil
62}
63
64func getMobTimerRoom(configuration config.Configuration) string {
65 if !isGit() {

Callers 4

TestTimerNumberLessThen1Function · 0.85
TestTimerNotANumberFunction · 0.85
TestTimerFunction · 0.85
StartTimerFunction · 0.85

Calls 12

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

Tested by 3

TestTimerNumberLessThen1Function · 0.68
TestTimerNotANumberFunction · 0.68
TestTimerFunction · 0.68