mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Implementing batch deletes for calls, logs and routes
Partially-Closes: #302
This commit is contained in:
@@ -118,5 +118,23 @@ func (m *metricds) DeleteLog(ctx context.Context, appName, callID string) error
|
|||||||
return m.ds.DeleteLog(ctx, appName, callID)
|
return m.ds.DeleteLog(ctx, appName, callID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *metricds) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, "ds_batch_delete_logs")
|
||||||
|
defer span.Finish()
|
||||||
|
return m.ds.BatchDeleteLogs(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *metricds) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, "ds_batch_delete_calls")
|
||||||
|
defer span.Finish()
|
||||||
|
return m.ds.BatchDeleteCalls(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *metricds) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, "ds_batch_delete_routes")
|
||||||
|
defer span.Finish()
|
||||||
|
return m.ds.BatchDeleteRoutes(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
// instant & no context ;)
|
// instant & no context ;)
|
||||||
func (m *metricds) GetDatabase() *sqlx.DB { return m.ds.GetDatabase() }
|
func (m *metricds) GetDatabase() *sqlx.DB { return m.ds.GetDatabase() }
|
||||||
|
|||||||
@@ -142,6 +142,18 @@ func (v *validator) DeleteLog(ctx context.Context, appName, callID string) error
|
|||||||
return v.Datastore.DeleteLog(ctx, appName, callID)
|
return v.Datastore.DeleteLog(ctx, appName, callID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *validator) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||||
|
return v.Datastore.BatchDeleteLogs(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *validator) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||||
|
return v.Datastore.BatchDeleteCalls(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *validator) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||||
|
return v.Datastore.BatchDeleteRoutes(ctx, appName)
|
||||||
|
}
|
||||||
|
|
||||||
// GetDatabase returns the underlying sqlx database implementation
|
// GetDatabase returns the underlying sqlx database implementation
|
||||||
func (v *validator) GetDatabase() *sqlx.DB {
|
func (v *validator) GetDatabase() *sqlx.DB {
|
||||||
return v.Datastore.GetDatabase()
|
return v.Datastore.GetDatabase()
|
||||||
|
|||||||
@@ -157,6 +157,28 @@ func (m *mock) GetCalls(ctx context.Context, filter *models.CallFilter) ([]*mode
|
|||||||
return m.Calls, nil
|
return m.Calls, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mock) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||||
|
newCalls := []*models.Call{}
|
||||||
|
for _, c := range m.Calls {
|
||||||
|
if c.AppName != appName {
|
||||||
|
newCalls = append(newCalls, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Calls = newCalls
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mock) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||||
|
newRoutes := []*models.Route{}
|
||||||
|
for _, c := range m.Routes {
|
||||||
|
if c.AppName != appName {
|
||||||
|
newRoutes = append(newRoutes, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.Routes = newRoutes
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetDatabase returns nil here since shouldn't really be used
|
// GetDatabase returns nil here since shouldn't really be used
|
||||||
func (m *mock) GetDatabase() *sqlx.DB {
|
func (m *mock) GetDatabase() *sqlx.DB {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -621,6 +621,24 @@ func (ds *sqlStore) DeleteLog(ctx context.Context, appName, callID string) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ds *sqlStore) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||||
|
query := ds.db.Rebind(`DELETE FROM logs WHERE app_name=?`)
|
||||||
|
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ds *sqlStore) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||||
|
query := ds.db.Rebind(`DELETE FROM calls WHERE app_name=?`)
|
||||||
|
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ds *sqlStore) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||||
|
query := ds.db.Rebind(`DELETE FROM routes WHERE app_name=?`)
|
||||||
|
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO scrap for sqlx scanx ?? some things aren't perfect (e.g. config is a json string)
|
// TODO scrap for sqlx scanx ?? some things aren't perfect (e.g. config is a json string)
|
||||||
type RowScanner interface {
|
type RowScanner interface {
|
||||||
Scan(dest ...interface{}) error
|
Scan(dest ...interface{}) error
|
||||||
|
|||||||
@@ -45,3 +45,12 @@ func (m *mock) DeleteLog(ctx context.Context, appName, callID string) error {
|
|||||||
delete(m.Logs, callID)
|
delete(m.Logs, callID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mock) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||||
|
for _, log := range m.Logs {
|
||||||
|
if log.AppName == appName {
|
||||||
|
m.DeleteLog(ctx, appName, log.CallID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ var possibleStatuses = [...]string{"delayed", "queued", "running", "success", "e
|
|||||||
type CallLog struct {
|
type CallLog struct {
|
||||||
CallID string `json:"call_id"`
|
CallID string `json:"call_id"`
|
||||||
Log string `json:"log"`
|
Log string `json:"log"`
|
||||||
|
AppName string `json:"app_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call is a representation of a specific invocation of a route.
|
// Call is a representation of a specific invocation of a route.
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ type Datastore interface {
|
|||||||
// calls exist, an empty list and a nil error are returned.
|
// calls exist, an empty list and a nil error are returned.
|
||||||
GetCalls(ctx context.Context, filter *CallFilter) ([]*Call, error)
|
GetCalls(ctx context.Context, filter *CallFilter) ([]*Call, error)
|
||||||
|
|
||||||
|
BatchDeleteCalls(ctx context.Context, appName string) error
|
||||||
|
BatchDeleteRoutes(ctx context.Context, appName string) error
|
||||||
// Implement LogStore methods for convenience
|
// Implement LogStore methods for convenience
|
||||||
LogStore
|
LogStore
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ type LogStore interface {
|
|||||||
// DeleteLog will remove the log at callID, it will not return an error if
|
// DeleteLog will remove the log at callID, it will not return an error if
|
||||||
// the log does not exist before removal.
|
// the log does not exist before removal.
|
||||||
DeleteLog(ctx context.Context, appName, callID string) error
|
DeleteLog(ctx context.Context, appName, callID string) error
|
||||||
|
|
||||||
|
BatchDeleteLogs(ctx context.Context, appName string) error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user