Skip to content

Commit

Permalink
Change how we store executions.
Browse files Browse the repository at this point in the history
This way the key could be ordered and ensure no collisions
  • Loading branch information
Victor Castell committed Aug 7, 2015
1 parent e615f51 commit a9da121
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions dcron/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ func (e *etcdClient) GetExecutions(jobName string) ([]*Execution, error) {
return executions, nil
}

func (e *etcdClient) SetExecution(execution *Execution) error {
// Save a new execution and returns the key of the new saved item or an error.
func (e *etcdClient) SetExecution(execution *Execution) (string, error) {
eJson, _ := json.Marshal(execution)
ts := fmt.Sprint(execution.StartedAt.UnixNano())
key := fmt.Sprintf("%d-%s", execution.StartedAt.UnixNano(), execution.NodeName)

log.Debugf("Setting etcd key %s: %s", execution.JobName, string(eJson))
if _, err := e.Client.Set(fmt.Sprintf(
"%s/executions/%s/%s", keyspace, execution.JobName, ts), string(eJson), 0); err != nil {
return err
res, err := e.Client.Set(fmt.Sprintf("%s/executions/%s/%s", keyspace, execution.JobName, key), string(eJson), 0)
if err != nil {
return "", err
}

return nil
return res.Node.Key, nil
}

func (e *etcdClient) GetLeader() string {
Expand Down

0 comments on commit a9da121

Please sign in to comment.