More advanced querying on JobListParams.Metadata()
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
调研方向
Start in job_list_params.go with JobListParams, NewJobListParams, Metadata, and toDBParams, then trace how client.JobList consumes the converted parameters. Review the proposed Where behavior alongside existing conditions and copying semantics. Done means the maintainer-approved API supports the metadata query example without breaking existing filters, with the requested documentation and tests.
由索引模型根据 Issue 内容生成。
描述
Right now JobListParams.Metadata() only offers querying via metadata >@ …, but I'd like to do slightly more advanced stuff. For example if the metadata contains:
{"object_id": 42}
And I'd like to list all jobs that match any of a set:
objectsUserHasAccessTo := []int{1, 5, 42}
params := NewJobListParams().Where(
`(metadata->'object_id')::int = any(@objects)`,
map[string]any{"objects": objectsUserHasAccessTo},
)
client.JobList(ctx, params)
I don't mind writing a patch for this; the simplest would be to just allow appending to the condition list and argument map, via the patch below. Although arguably that would give too much control (and the ability to do very stupid things).
Then again, restricting this would probably more trouble than its worth(?) The alternative is writing my own query from scratch, which allows for even more stupid stuff.
Well, let me know what you want and I'll submit a working patch with docs, tests, etc.
diff --git i/job_list_params.go w/job_list_params.go
index ffdc39a..7edd6f9 100644
--- i/job_list_params.go
+++ w/job_list_params.go
@@ -174,6 +174,8 @@ type JobListParams struct {
sortField JobListOrderByField
sortOrder SortOrder
states []rivertype.JobState
+ whereSQL string
+ whereArgs map[string]any
}
// NewJobListParams creates a new JobListParams to return available jobs sorted
@@ -263,6 +265,12 @@ func (p *JobListParams) toDBParams() (*dblist.JobListParams, error) {
conditions = append(conditions, `metadata @> @metadata_fragment::jsonb`)
namedArgs["metadata_fragment"] = p.metadataFragment
}
+ if p.whereSQL != "" {
+ conditions = append(conditions, p.whereSQL)
+ for k, v := range p.whereArgs {
+ namedArgs[k] = v
+ }
+ }
if p.after != nil {
if p.after.time.IsZero() { // order by ID only
@@ -346,6 +354,13 @@ func (p *JobListParams) Metadata(json string) *JobListParams {
return paramsCopy
}
+func (p *JobListParams) Where(sql string, args map[string]any) *JobListParams {
+ paramsCopy := p.copy()
+ paramsCopy.whereSQL = sql
+ paramsCopy.whereArgs = args
+ return paramsCopy
+}
+
// Queues returns an updated filter set that will only return jobs from the
// given queues.
func (p *JobListParams) Queues(queues ...string) *JobListParams {
- 主要语言
- Go
- 星标
- 5.7k
- 派生
- 179
- 平均合并
- 2 天 19 小时
- 30 天内合并 PR
- 12
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
riverqueue/river 的其他 Issue
-
难度 5/5 一周以上 新手友好度 45/100
riverqueue/river#1358 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
riverqueue/river#1258 · 7 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
riverqueue/river#1225 · 14 条评论 ·
-
难度 4/5 3-5 天 新手友好度 52/100
riverqueue/river#1185 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 52/100
riverqueue/river#1183 · 2 个 reaction ·
相似的 Issue
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 76/100
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/agent-framework-go#1179 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
[Bug]: OLLAMA_KEEP_ALIVE="5m" / "24h" crashes Ollama embedding and vision models with ValueError 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
infiniflow/ragflow#20223 · 1 个 reaction ·
-
bug needs triage pkg/translator/faro
难度 2/5 1-3 小时 新手友好度 88/100
open-telemetry/opentelemetry-collector-contrib#51484 · 1 条评论 ·