func (v *Run) Run(c cli.Command) { jobName := c.Param("jobname").String() log.WithFields( log.Fields{ "pkg": "command", "func": "Run", "job": jobName, }, ).Info("Starting job") j := job.New(metl.GetJobFilePath(jobName)) j.Lock() jf, err := j.Fetch() if err != nil { log.Fatal("Error fetching job:", err) } jf.Run() j.Unlock() j.Done(jf) // log stats, notify of errors etc // notify of any errors // log stats to dashboard, number of processed, rejected rows etc. // if parsing option is empty then, we just download the file }
func (v *Add) Run(c cli.Command) { jobName := c.Param("jobname").String() var job job.Job if _, err := toml.DecodeFile(metl.GetJobFilePath(jobName)+".toml", &job); err != nil { log.Fatal(err) } cronfile := filepath.Join(metl.Etl.GetLocalStoragePath(), crontabFile) file, err := os.Open(cronfile) if err != nil { file, err = os.Create(cronfile) if err != nil { log.WithFields( log.Fields{ "filename": cronfile, }, ).Fatal("Unable to create cronfile: ", err) } } defer file.Close() err = syscall.Flock(int(file.Fd()), syscall.LOCK_EX) if err != nil { log.Fatal("Failed to lock file") } defer func() { err = syscall.Flock(int(file.Fd()), syscall.LOCK_UN) if err != nil { log.Fatal("Failed to unlock file") } }() buffer := make([]string, 0) if err = jobIsInFile(file, jobName, &buffer); err != nil { log.Fatal(err) } buffer = append(buffer, fmt.Sprintf("%s %s >> %s%s.log", cmd, jobName, logDir, jobName)) tmpf, err := ioutil.TempFile(metl.Etl.GetLocalStoragePath(), "tmp") if err != nil { log.Fatal("Unable to create temporary file.") } for _, line := range buffer { if _, err := tmpf.WriteString(line + "\n"); err != nil { log.Fatal("Unable to write to temporary file") } } if err := os.Rename(tmpf.Name(), cronfile); err != nil { log.Fatal("Failed to rename temporary lock file:", err) } // execute /usr/bin/env crontab cronfile }