More advanced querying on JobListParams.Metadata()
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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 {
- Langage dominant
- Go
- Étoiles
- 5.8k
- Forks
- 188
- Merge moyen
- 22 h 44 min
- PR mergées (30 j)
- 95
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de riverqueue/river
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
riverqueue/river#1454 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 52/100
riverqueue/river#1411 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Remote JobCancel() can be silently lost while the notifier is reconnecting (no durable-poll fallback)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 45/100
riverqueue/river#1358 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
River job stuck at runningOuverte
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
riverqueue/river#1258 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
riverqueue/river#1225 · 14 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de riverqueue/river
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
ViewData can pair the in-flight proposal with the prepared flag of another proposalPeut-être pris @HagarMeir l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
hyperledger/SmartBFT#710 ·
Les mainteneurs répondent en général sous 1 jour
-
agent-butler-finding chore
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
jordansmall/spindrift#5575 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
open-telemetry/opentelemetry-go-compile-instrumentation#1512 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
OpenPrinting/go-mfp#124 ·
Les mainteneurs répondent en général sous 1 jour