MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / processCrontab

Function processCrontab

cmd/discover.go:356–570  ·  view source on GitHub ↗
(crontab *lib.Crontab)

Source from the content-addressed store, hash-verified

354}
355
356func processCrontab(crontab *lib.Crontab) bool {
357 defer printLn()
358
359 if !crontab.Exists() {
360 printWarningText("This crontab does not exist. Skipping.", true)
361 return false
362 }
363
364 // This will mostly happen when the crontab is empty
365 if err, _ := crontab.Parse(noAutoDiscover); err != nil {
366 printWarningText("This crontab is empty. Skipping.", true)
367 log(fmt.Sprintf("Skipping %s: %s", crontab.DisplayName(), err.Error()))
368 return false
369 }
370
371 // Before going further, ensure we aren't going to run into permissions problems writing the crontab later
372 if !crontab.IsWritable() {
373 printWarningText(fmt.Sprintf("This crontab is not writeable. Re-run command with sudo. Skipping"), true)
374 return false
375 }
376
377 // If a timezone env var is set in the crontab it takes precedence over system tz
378 if crontab.TimezoneLocationName != nil {
379 timezone = *crontab.TimezoneLocationName
380 } else {
381 timezone = effectiveTimezoneLocationName()
382 }
383
384 // This is done entirely so we can print a summary line with a count of cron jobs found in this crontab
385 if !isAutoDiscover {
386 count := 0
387 for _, line := range crontab.Lines {
388 if line.IsMonitorable() && !line.IsAutoDiscoverCommand() {
389 count++
390 }
391 }
392
393 label := "jobs"
394 if count == 1 {
395 label = "job"
396 }
397 printSuccessText(fmt.Sprintf("Found %d %s in %s", count, label, crontab.DisplayName()), true)
398 }
399
400 // Read crontab into map of Monitor structs
401 monitors := map[string]*lib.Monitor{}
402 allNameCandidates := map[string]bool{}
403 userExited := false
404
405 for _, line := range crontab.Lines {
406 if !line.IsMonitorable() {
407 continue
408 }
409
410 // Automatically skip jobs marked with "# cronitor: ignore"
411 if line.Ignored {
412 continue
413 }

Callers 2

discover.goFile · 0.85
processDirectoryFunction · 0.85

Calls 15

printLnFunction · 0.85
printWarningTextFunction · 0.85
logFunction · 0.85
printSuccessTextFunction · 0.85
createDefaultNameFunction · 0.85
effectiveHostnameFunction · 0.85
createTagsFunction · 0.85
renderJobInfoBoxFunction · 0.85
initialNameInputModelFunction · 0.85
printErrorTextFunction · 0.85
createNoteFunction · 0.85

Tested by

no test coverage detected