Skip to content

Commit bbe1c3c

Browse files
committed
Enforce project concurrency on query
1 parent 8cf9452 commit bbe1c3c

File tree

4 files changed

+216
-102
lines changed

4 files changed

+216
-102
lines changed

config/config.exs

-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ config :tesla, adapter: {Tesla.Adapter.Finch, name: Lightning.Finch}
162162
config :lightning, :is_resettable_demo, false
163163
config :lightning, :default_retention_period, nil
164164

165-
config :lightning, Lightning.Runtime.RuntimeManager, start: false
166-
167165
config :lightning, LightningWeb.CollectionsController,
168166
default_stream_limit: 1_000,
169167
max_database_limit: 500

lib/lightning/projects/project.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ defmodule Lightning.Projects.Project do
7474
changeset
7575
|> validate_length(:description, max: 240)
7676
|> validate_required([:name])
77-
|> validate_format(:name, ~r/^[a-z\-\d]+$/)
77+
|> validate_format(:name, ~r/^[A-Z]*[a-z\-\d]+$/)
7878
|> validate_dataclip_retention_period()
7979
|> validate_inclusion(:history_retention_period, data_retention_options())
8080
|> validate_inclusion(:dataclip_retention_period, data_retention_options())

lib/lightning/runs/query.ex

+9-15
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,19 @@ defmodule Lightning.Runs.Query do
8585
join: w in assoc(wo, :workflow),
8686
join: p in assoc(w, :project)
8787
)
88-
|> windows([r, _wo, w, p],
89-
row_number: [
90-
partition_by:
91-
fragment(
92-
"CASE WHEN ? IS NOT NULL THEN ? ELSE ? END",
93-
w.concurrency,
94-
w.id,
95-
p.id
96-
),
97-
order_by: [asc: r.inserted_at]
98-
]
99-
)
10088
|> select([r, _wo, w, p], %{
10189
id: r.id,
10290
state: r.state,
10391
# need to check what performance implications are of using row_number
10492
# does the subsequent query's limit clause get applied to the row_number
10593
# calculated here?
106-
row_number: row_number() |> over(:row_number),
94+
w_row_number:
95+
row_number() |> over(partition_by: w.id, order_by: r.inserted_at),
96+
p_row_number:
97+
row_number() |> over(partition_by: p.id, order_by: r.inserted_at),
10798
project_id: w.project_id,
108-
concurrency: coalesce(w.concurrency, p.concurrency),
99+
w_concurrency: coalesce(w.concurrency, p.concurrency),
100+
p_concurrency: coalesce(p.concurrency, 100),
109101
inserted_at: r.inserted_at
110102
})
111103
end
@@ -136,7 +128,9 @@ defmodule Lightning.Runs.Query do
136128
|> where(
137129
[r, ipw],
138130
r.state == :available and
139-
(is_nil(ipw.concurrency) or ipw.row_number <= ipw.concurrency)
131+
(is_nil(ipw.w_concurrency) or
132+
(ipw.w_row_number <= ipw.w_concurrency and
133+
ipw.p_row_number <= ipw.p_concurrency))
140134
)
141135
|> order_by([r], asc: r.inserted_at)
142136
end

0 commit comments

Comments
 (0)