job.go 814 B

12345678910111213141516171819202122232425262728293031
  1. package schema
  2. import (
  3. "context"
  4. "github.com/gravitl/netmaker/db"
  5. "time"
  6. )
  7. // Job represents a task that netmaker server
  8. // wants to do.
  9. //
  10. // Ideally, a jobs table should have details
  11. // about its type, status, who initiated it,
  12. // etc. But, for now, the table only contains
  13. // records of jobs that have been done, so
  14. // that it is easier to prevent a task from
  15. // being executed again.
  16. type Job struct {
  17. ID string `gorm:"primaryKey"`
  18. CreatedAt time.Time
  19. }
  20. // Create creates a job record in the jobs table.
  21. func (j *Job) Create(ctx context.Context) error {
  22. return db.FromContext(ctx).Model(&Job{}).Create(j).Error
  23. }
  24. // Get returns a job record with the given Job.ID.
  25. func (j *Job) Get(ctx context.Context) error {
  26. return db.FromContext(ctx).Model(&Job{}).Where("id = ?", j.ID).First(j).Error
  27. }