-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
48 lines (39 loc) · 927 Bytes
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package reflektor
import (
"fmt"
"gopkg.in/robfig/cron.v2"
"os"
)
// Job represents a scheduled archival job
type Job struct {
ID cron.EntryID
Name string
SourcePath string
Schedule string
}
// NewJob builds an instance of a Job from the supplied config
func NewJob(config JobConfig) *Job {
job := &Job{
Name: config.Name,
SourcePath: config.SourcePath,
Schedule: config.Schedule,
}
return job
}
// SourceExists returns true if the job's source path is present
func (j *Job) SourceExists() bool {
if _, err := os.Stat(j.SourcePath); os.IsNotExist(err) {
return false
}
return true
}
// ArchiveExists returns true if a job's existing archive is present
func (j *Job) ArchiveExists() bool {
if _, err := os.Stat(j.ArchivePath()); os.IsNotExist(err) {
return false
}
return true
}
func (j *Job) ArchivePath() string {
return fmt.Sprintf("/archives/%s.tar.gz", j.Name)
}