Skip to content

Commit

Permalink
fix rollouts, chart installer
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Sep 23, 2022
1 parent fb0fe7c commit 65568a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
7 changes: 7 additions & 0 deletions apps/core/lib/core/schema/rollout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Core.Schema.Rollout do
alias Piazza.Ecto.UUID
alias Core.Schema.{Repository}

@expiry -14

defenum Status, queued: 0, running: 1, finished: 2

schema "rollouts" do
Expand All @@ -17,6 +19,11 @@ defmodule Core.Schema.Rollout do
timestamps()
end

def expired(query \\ __MODULE__) do
expiry = Timex.now() |> Timex.shift(days: @expiry)
from(r in query, where: r.inserted_at < ^expiry)
end

def for_repository(query \\ __MODULE__, id) do
from(r in query, where: r.repository_id == ^id)
end
Expand Down
2 changes: 1 addition & 1 deletion apps/core/lib/core/services/rollouts/rollable/versions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defimpl Core.Rollouts.Rollable, for: [Core.PubSub.VersionCreated, Core.PubSub.Ve
def process(%{item: version}, %{installation: %{user: user}} = inst) do
case Dependencies.valid?(version.dependencies, user) do
true -> directly_install(version, inst)
false -> Upgrades.create_deferred_update(version.id, inst, user)
_ -> Upgrades.create_deferred_update(version.id, inst, user)
end
end

Expand Down
25 changes: 13 additions & 12 deletions www/src/components/repos/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import moment from 'moment'

import { A, Flex } from 'honorable'

import { updateCache } from 'utils/graphql'

import {
ResponsiveLayoutContentContainer,
ResponsiveLayoutSidecarContainer,
Expand Down Expand Up @@ -72,26 +74,19 @@ function ChartInfo({ version: { helm, insertedAt } }) {
)
}

function ChartInstaller({ chart }) {
function ChartInstaller({ chart, version }) {
const [mutation, { error }] = useMutation(chart.installation ? UPDATE_CHART_INST : INSTALL_CHART, {
variables: {
id: chart.installation ? chart.installation.id : chart.repository.installation.id,
attributes: { chartId: chart.id, versionId: chart.installation?.version?.id },
attributes: { chartId: chart.id, versionId: version.id },
},
update: (cache, { data }) => {
const ci = data.installChart || data.updateChartInstallation
const prev = cache.readQuery({ query: CHART_Q, variables: { chartId: chart.id } })

cache.writeQuery({
updateCache(cache, {
query: CHART_Q,
variables: { chartId: chart.id },
data: {
...prev,
chart: {
...prev.chart,
installation: ci,
},
},
update: prev => ({ ...prev, chart: { ...prev.chart, installation: ci } }),
})
},
})
Expand All @@ -112,7 +107,13 @@ export function ChartActions({ chart, currentVersion, ...props }) {
return null
}

return <Box {...props}><ChartInstaller chart={chart} /></Box>
return (
<Box {...props}><ChartInstaller
chart={chart}
version={currentVersion}
/>
</Box>
)
}

function ImageDependencies({ version: { imageDependencies } }) {
Expand Down

0 comments on commit 65568a3

Please sign in to comment.