Skip to content

Commit fd153f9

Browse files
committed
refactor: use idlestate instead of idled
1 parent 21c41cc commit fd153f9

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

services/actions-handler/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/uselagoon/lagoon/services/actions-handler
22

3-
go 1.25
3+
go 1.24.0
44

55
require (
66
github.com/aws/aws-sdk-go v1.55.8
77
github.com/cheshir/go-mq/v2 v2.0.1
8-
github.com/uselagoon/machinery v0.0.35-0.20251124010253-71bebf6d6966
8+
github.com/uselagoon/machinery v0.0.35-0.20260127223824-7bf0210c35ef
99
gopkg.in/matryer/try.v1 v1.0.0-20150601225556-312d2599e12e
1010
)
1111

@@ -16,7 +16,7 @@ require (
1616
github.com/google/go-cmp v0.7.0 // indirect
1717
github.com/google/uuid v1.6.0 // indirect
1818
github.com/guregu/null v4.0.0+incompatible // indirect
19-
github.com/hashicorp/go-version v1.7.0 // indirect
19+
github.com/hashicorp/go-version v1.8.0 // indirect
2020
github.com/jmespath/go-jmespath v0.4.0 // indirect
2121
github.com/machinebox/graphql v0.2.3-0.20181106130121-3a9253180225 // indirect
2222
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 // indirect

services/actions-handler/go.sum

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
528528
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
529529
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
530530
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
531-
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
532-
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
531+
github.com/hashicorp/go-version v1.8.0 h1:KAkNb1HAiZd1ukkxDFGmokVZe1Xy9HG6NUp+bPle2i4=
532+
github.com/hashicorp/go-version v1.8.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
533533
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
534534
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
535535
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
@@ -850,8 +850,8 @@ github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/
850850
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
851851
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
852852
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
853-
github.com/uselagoon/machinery v0.0.35-0.20251124010253-71bebf6d6966 h1:zfOFGy2aaAn5SnGoOBn/GqmiPzQKY4Crd5A0Y+DXI90=
854-
github.com/uselagoon/machinery v0.0.35-0.20251124010253-71bebf6d6966/go.mod h1:G0ujppuNR0BrtAnlmH8xDb9TDfayb4A36aeo0DYg7fQ=
853+
github.com/uselagoon/machinery v0.0.35-0.20260127223824-7bf0210c35ef h1:Pi47at1nuQ6cPbOGKikLM2DOtmEO6gmH6Vvx6ZZ/KuY=
854+
github.com/uselagoon/machinery v0.0.35-0.20260127223824-7bf0210c35ef/go.mod h1:ptpaZ3HGGDc5cfnII4QOhereQvsipN8TSAlUhyy99xU=
855855
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
856856
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
857857
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
@@ -1041,7 +1041,6 @@ golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qx
10411041
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
10421042
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
10431043
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1044-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
10451044
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
10461045
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
10471046
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1167,8 +1166,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
11671166
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11681167
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11691168
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1170-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
1171-
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1169+
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
1170+
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
11721171
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
11731172
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
11741173
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

services/actions-handler/handler/controller_idling.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
"github.com/uselagoon/machinery/utils/jwt"
1616
)
1717

18-
type Idled struct {
19-
Idled bool `json:"idled"`
20-
}
21-
2218
type ServiceState struct {
2319
Name string `json:"name"`
2420
Type string `json:"type"`
@@ -76,10 +72,10 @@ func (m *Messenger) handleIdling(ctx context.Context, messageQueue *mq.MessageQu
7672
environmentID = *message.Meta.EnvironmentID
7773
}
7874
decodeData, _ := base64.StdEncoding.DecodeString(message.Meta.AdvancedData)
79-
idled := &Idled{}
75+
idled := &schema.Idled{}
8076
json.Unmarshal(decodeData, idled)
8177
updateEnvironmentPatch := schema.UpdateEnvironmentPatchInput{
82-
Idled: &idled.Idled,
78+
IdleState: &idled.IdleState,
8379
}
8480
updateEnvironment, err := lagoon.UpdateEnvironment(ctx, environmentID, updateEnvironmentPatch, l)
8581
if err != nil {

services/api/database/migrations/20251120000000_environment_idling_status.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
exports.up = async function(knex) {
66
return knex.schema
77
.alterTable('environment', (table) => {
8-
table.boolean('idled').notNullable().defaultTo(0);
8+
table.string('idle_state').notNullable().defaultTo('active');
99
})
1010
.alterTable('environment_service', function (table) {
1111
table.integer('replicas').notNullable().defaultTo(0);
@@ -19,7 +19,7 @@ exports.up = async function(knex) {
1919
exports.down = async function(knex) {
2020
return knex.schema
2121
.alterTable('environment', (table) => {
22-
table.dropColumn('idled');
22+
table.dropColumn('idle_state');
2323
})
2424
.alterTable('environment_service', (table) => {
2525
table.dropColumn('replicas');

services/api/src/resolvers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ async function getResolvers() {
521521
START: 'start',
522522
RESTART: 'restart',
523523
},
524+
IdleState: {
525+
ACTIVE: 'active',
526+
IDLED: 'idled',
527+
SCALED: 'scaled',
528+
},
524529
Openshift: {
525530
projectUser: getProjectUser,
526531
token: getToken,

services/api/src/resources/environment/resolvers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ export const updateEnvironment: ResolverFn = async (
816816
routes: input.patch.routes,
817817
autoIdle: input.patch.autoIdle,
818818
created: input.patch.created,
819-
idled: input.patch.idled
819+
idleState: input.patch.idleState
820820
}
821821
})
822822
);
@@ -859,7 +859,7 @@ export const updateEnvironment: ResolverFn = async (
859859
routes: input.patch.routes,
860860
autoIdle: input.patch.autoIdle,
861861
created: input.patch.created,
862-
idled: input.patch.idled
862+
idleState: input.patch.idleState
863863
},
864864
data: withK8s,
865865
...auditLog,
@@ -1212,12 +1212,12 @@ export const idleOrUnidleEnvironment = async (
12121212
}
12131213

12141214
// don't try idle if the environment is already idled or unidled
1215-
if (environmentData.idled && idle) {
1215+
if (environmentData.idleState != 'active' && idle) {
12161216
throw new Error(
12171217
`Environment is already idled`
12181218
);
12191219
}
1220-
if (!environmentData.idled && !idle) {
1220+
if (environmentData.idleState == 'active' && !idle) {
12211221
throw new Error(
12221222
`Environment is already unidled`
12231223
);
@@ -1296,7 +1296,7 @@ export const stopOrStartEnvironmentService = async (
12961296
`Unauthorized: You don't have permission to "restart" on "environment_state"`
12971297
);
12981298
}
1299-
if (environmentData.idled) {
1299+
if (environmentData.idleState != 'active') {
13001300
throw new Error(
13011301
`Can't perform action because the environment is idled`
13021302
);

services/api/src/typeDefs.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,9 @@ const typeDefs = gql`
926926
autogeneratedPathRoutes: [AutogeneratedPathRoute]
927927
disableRequestVerification: Boolean
928928
"""
929-
Is the environment currently idled
929+
The idle state of the environment
930930
"""
931-
idled: Boolean
931+
idleState: IdleState
932932
}
933933
934934
type EnvironmentPendingChanges {
@@ -2587,14 +2587,20 @@ const typeDefs = gql`
25872587
autogeneratedRoutes: Boolean
25882588
autogeneratedPathRoutes: [AutogeneratedPathRouteInput]
25892589
disableRequestVerification: Boolean
2590-
idled: Boolean
2590+
idleState: IdleState
25912591
}
25922592
25932593
input UpdateEnvironmentInput {
25942594
id: Int!
25952595
patch: UpdateEnvironmentPatchInput
25962596
}
25972597
2598+
enum IdleState {
2599+
ACTIVE
2600+
IDLED
2601+
SCALED
2602+
}
2603+
25982604
input EnvVariableInput {
25992605
id: Int
26002606
type: EnvVariableType

0 commit comments

Comments
 (0)