Make call.End more solid

This commit is contained in:
Denis Makogon
2017-09-06 02:00:33 +03:00
parent d91d0fe79b
commit 6a541139a9
4 changed files with 11 additions and 16 deletions

View File

@@ -224,7 +224,9 @@ func (a *agent) Submit(callI Call) error {
// TODO if the context is timed out here we need to allocate some more time...
// right now this only works b/c the db isn't using the context
return call.End(ctx, err)
call.End(ctx, err)
return err
}
// getSlot must ensure that if it receives a slot, it will be returned, otherwise

View File

@@ -35,7 +35,7 @@ type Call interface {
// regardless of whether the execution failed or not. An error will be passed
// to End, which if nil indicates a successful execution. Any error returned
// from End will be returned as the error from Submit.
End(ctx context.Context, err error) error
End(ctx context.Context, err error)
}
// TODO build w/o closures... lazy
@@ -267,7 +267,7 @@ func (c *call) Start(ctx context.Context) error {
return nil
}
func (c *call) End(ctx context.Context, err error) error {
func (c *call) End(ctx context.Context, err error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "agent_call_end")
defer span.Finish()
@@ -287,19 +287,13 @@ func (c *call) End(ctx context.Context, err error) error {
// XXX (reed): delete MQ message, eventually
}
// TODO since the function itself can reply directly to a client (or logs),
// this means that we could potentially store an error / timeout status for a
// call that ran successfully [by a user's perspective]
// TODO this should be update, really
if err := c.ds.InsertCall(ctx, c.Call); err != nil {
// TODO we should just log this error not return it to user? just issue storing call status but call is run
// need newer context because original one may be modified
// and no longer be valid for further context-bound operations
if err := c.ds.InsertCall(context.Background(), c.Call); err != nil {
// TODO we should just log this error not return it to user?
// just issue storing call status but call is run
logrus.WithError(err).Error("error inserting call into datastore")
}
// return the original error so that this is returned from Submit (for sync)
// TODO we could just skip over (and log) and End errors and return slot.exec error
// in submit instead of doing this, it's a bit odd. thoughts?
return err
}
func (a *agent) route(ctx context.Context, appName, path string) (*models.Route, error) {