feat: add priority demotion controls
This commit is contained in:
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -67,6 +68,8 @@ type Platform struct {
|
||||
AuthType string `json:"authType"`
|
||||
Status string `json:"status"`
|
||||
Priority int `json:"priority"`
|
||||
DynamicPriority *int `json:"dynamicPriority,omitempty"`
|
||||
EffectivePriority int `json:"effectivePriority"`
|
||||
DefaultPricingMode string `json:"defaultPricingMode"`
|
||||
DefaultDiscountFactor float64 `json:"defaultDiscountFactor"`
|
||||
PricingRuleSetID string `json:"pricingRuleSetId,omitempty"`
|
||||
@@ -508,13 +511,14 @@ type TaskParamPreprocessingLog struct {
|
||||
|
||||
func (s *Store) ListPlatforms(ctx context.Context) ([]Platform, error) {
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status, priority,
|
||||
SELECT id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status,
|
||||
priority, dynamic_priority, COALESCE(dynamic_priority, priority),
|
||||
default_pricing_mode, default_discount_factor::float8, COALESCE(pricing_rule_set_id::text, ''),
|
||||
config, credentials, retry_policy, rate_limit_policy,
|
||||
COALESCE(to_char(cooldown_until AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), ''),
|
||||
created_at, updated_at
|
||||
FROM integration_platforms
|
||||
ORDER BY priority ASC, created_at DESC`)
|
||||
ORDER BY COALESCE(dynamic_priority, priority) ASC, priority ASC, created_at DESC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -527,6 +531,7 @@ ORDER BY priority ASC, created_at DESC`)
|
||||
var credentialsBytes []byte
|
||||
var retryPolicyBytes []byte
|
||||
var rateLimitPolicyBytes []byte
|
||||
var dynamicPriority sql.NullInt64
|
||||
if err := rows.Scan(
|
||||
&platform.ID,
|
||||
&platform.Provider,
|
||||
@@ -537,6 +542,8 @@ ORDER BY priority ASC, created_at DESC`)
|
||||
&platform.AuthType,
|
||||
&platform.Status,
|
||||
&platform.Priority,
|
||||
&dynamicPriority,
|
||||
&platform.EffectivePriority,
|
||||
&platform.DefaultPricingMode,
|
||||
&platform.DefaultDiscountFactor,
|
||||
&platform.PricingRuleSetID,
|
||||
@@ -550,6 +557,7 @@ ORDER BY priority ASC, created_at DESC`)
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
platform.DynamicPriority = intPointerFromNull(dynamicPriority)
|
||||
platform.Config = decodeObject(configBytes)
|
||||
platform.CredentialsPreview = maskCredentialsPreview(credentialsBytes)
|
||||
platform.RetryPolicy = decodeObject(retryPolicyBytes)
|
||||
@@ -578,6 +586,7 @@ func (s *Store) CreatePlatform(ctx context.Context, input CreatePlatformInput) (
|
||||
var credentialsResultBytes []byte
|
||||
var retryPolicyBytes []byte
|
||||
var rateLimitPolicyBytes []byte
|
||||
var dynamicPriority sql.NullInt64
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
INSERT INTO integration_platforms (
|
||||
provider, platform_key, name, internal_name, base_url, auth_type, credentials, config,
|
||||
@@ -588,7 +597,8 @@ VALUES (
|
||||
$1, COALESCE(NULLIF($2, ''), 'platform_' || replace(gen_random_uuid()::text, '-', '')), $3, NULLIF($4, ''), $5, $6, $7, $8,
|
||||
$9, $10, NULLIF($11, '')::uuid, $12, $13, $14
|
||||
)
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status, priority,
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status,
|
||||
priority, dynamic_priority, COALESCE(dynamic_priority, priority),
|
||||
default_pricing_mode, default_discount_factor::float8, COALESCE(pricing_rule_set_id::text, ''),
|
||||
config, credentials, retry_policy, rate_limit_policy,
|
||||
COALESCE(to_char(cooldown_until AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), ''),
|
||||
@@ -606,6 +616,8 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
&platform.AuthType,
|
||||
&platform.Status,
|
||||
&platform.Priority,
|
||||
&dynamicPriority,
|
||||
&platform.EffectivePriority,
|
||||
&platform.DefaultPricingMode,
|
||||
&platform.DefaultDiscountFactor,
|
||||
&platform.PricingRuleSetID,
|
||||
@@ -620,6 +632,7 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
if err != nil {
|
||||
return Platform{}, err
|
||||
}
|
||||
platform.DynamicPriority = intPointerFromNull(dynamicPriority)
|
||||
platform.Config = decodeObject(configBytes)
|
||||
platform.CredentialsPreview = maskCredentialsPreview(credentialsResultBytes)
|
||||
platform.RetryPolicy = decodeObject(retryPolicyBytes)
|
||||
@@ -650,6 +663,7 @@ func (s *Store) UpdatePlatform(ctx context.Context, id string, input CreatePlatf
|
||||
var credentialsResultBytes []byte
|
||||
var retryPolicyBytes []byte
|
||||
var rateLimitPolicyBytes []byte
|
||||
var dynamicPriority sql.NullInt64
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
UPDATE integration_platforms
|
||||
SET provider = $2,
|
||||
@@ -672,7 +686,8 @@ SET provider = $2,
|
||||
rate_limit_policy = $15,
|
||||
updated_at = now()
|
||||
WHERE id = $1::uuid
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status, priority,
|
||||
RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), COALESCE(base_url, ''), auth_type, status,
|
||||
priority, dynamic_priority, COALESCE(dynamic_priority, priority),
|
||||
default_pricing_mode, default_discount_factor::float8, COALESCE(pricing_rule_set_id::text, ''),
|
||||
config, credentials, retry_policy, rate_limit_policy,
|
||||
COALESCE(to_char(cooldown_until AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'), ''),
|
||||
@@ -702,6 +717,8 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
&platform.AuthType,
|
||||
&platform.Status,
|
||||
&platform.Priority,
|
||||
&dynamicPriority,
|
||||
&platform.EffectivePriority,
|
||||
&platform.DefaultPricingMode,
|
||||
&platform.DefaultDiscountFactor,
|
||||
&platform.PricingRuleSetID,
|
||||
@@ -716,6 +733,7 @@ RETURNING id::text, provider, platform_key, name, COALESCE(internal_name, ''), C
|
||||
if err != nil {
|
||||
return Platform{}, err
|
||||
}
|
||||
platform.DynamicPriority = intPointerFromNull(dynamicPriority)
|
||||
platform.Config = decodeObject(configBytes)
|
||||
platform.CredentialsPreview = maskCredentialsPreview(credentialsResultBytes)
|
||||
platform.RetryPolicy = decodeObject(retryPolicyBytes)
|
||||
|
||||
Reference in New Issue
Block a user