mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
feat(agent): Add shutdown lifecycle states and shutdown_script support (#6139)
* feat(api): Add agent shutdown lifecycle states * feat(agent): Add shutdown_script support * feat(agent): Add shutdown_script timeout * feat(site): Support new agent lifecycle states --- Co-authored-by: Marcin Tojek <marcin@coder.com>
This commit is contained in:
committed by
GitHub
parent
02100c64b5
commit
22e3ff96be
@ -0,0 +1,12 @@
|
||||
ALTER TABLE workspace_agents DROP COLUMN shutdown_script;
|
||||
|
||||
ALTER TABLE workspace_agents DROP COLUMN shutdown_script_timeout_seconds;
|
||||
|
||||
-- We can't drop values from enums, so we have to create a new one and convert the data.
|
||||
UPDATE workspace_agents SET lifecycle_state = 'ready' WHERE lifecycle_state IN ('shutting_down', 'shutdown_timeout', 'shutdown_error', 'off');
|
||||
ALTER TYPE workspace_agent_lifecycle_state RENAME TO workspace_agent_lifecycle_state_old;
|
||||
CREATE TYPE workspace_agent_lifecycle_state AS ENUM ('created', 'starting', 'start_timeout', 'start_error', 'ready');
|
||||
ALTER TABLE workspace_agents ALTER COLUMN lifecycle_state DROP DEFAULT;
|
||||
ALTER TABLE workspace_agents ALTER COLUMN lifecycle_state TYPE workspace_agent_lifecycle_state USING lifecycle_state::text::workspace_agent_lifecycle_state;
|
||||
ALTER TABLE workspace_agents ALTER COLUMN lifecycle_state SET DEFAULT 'created';
|
||||
DROP TYPE workspace_agent_lifecycle_state_old;
|
@ -0,0 +1,14 @@
|
||||
ALTER TABLE workspace_agents ADD COLUMN shutdown_script varchar(65534);
|
||||
|
||||
COMMENT ON COLUMN workspace_agents.shutdown_script IS 'Script that is executed before the agent is stopped.';
|
||||
|
||||
-- Disable shutdown script timeouts by default.
|
||||
ALTER TABLE workspace_agents ADD COLUMN shutdown_script_timeout_seconds int4 NOT NULL DEFAULT 0;
|
||||
|
||||
COMMENT ON COLUMN workspace_agents.shutdown_script_timeout_seconds IS 'The number of seconds to wait for the shutdown script to complete. If the script does not complete within this time, the agent lifecycle will be marked as shutdown_timeout.';
|
||||
|
||||
-- Add enum fields
|
||||
ALTER TYPE workspace_agent_lifecycle_state ADD VALUE 'shutting_down';
|
||||
ALTER TYPE workspace_agent_lifecycle_state ADD VALUE 'shutdown_timeout';
|
||||
ALTER TYPE workspace_agent_lifecycle_state ADD VALUE 'shutdown_error';
|
||||
ALTER TYPE workspace_agent_lifecycle_state ADD VALUE 'off';
|
2
coderd/database/migrations/testdata/fixtures/000091_lifecycle.up.sql
vendored
Normal file
2
coderd/database/migrations/testdata/fixtures/000091_lifecycle.up.sql
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
-- Set a non-default lifecycle_state.
|
||||
UPDATE workspace_agents SET lifecycle_state = 'ready' WHERE id = '7a1ce5f8-8d00-431c-ad1b-97a846512804';
|
2
coderd/database/migrations/testdata/fixtures/000104_lifecycle.up.sql
vendored
Normal file
2
coderd/database/migrations/testdata/fixtures/000104_lifecycle.up.sql
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
-- Set lifecycle_state to enum value not available in previous migration.
|
||||
UPDATE workspace_agents SET lifecycle_state = 'off' WHERE id = '7a1ce5f8-8d00-431c-ad1b-97a846512804';
|
Reference in New Issue
Block a user