Some checks failed
Integration Tests / integration-test (push) Failing after -23m59s
This commit introduces a comprehensive integration test suite for the pgsql-broker. The test suite includes: - A Docker/Podman environment for running a PostgreSQL database, managed via a . - Integration tests that cover the broker's lifecycle, including job creation, execution, and instance management. - A GitHub Actions workflow to automate the execution of all tests on push and pull requests. - A dedicated test configuration file () and helper test files. refactor(worker): fix job processing transaction - The worker's job processing now uses a single transaction to fetch and run a job, resolving a race condition where jobs were not in the 'running' state when being executed. - The broker's database instance registration is now more robust, handling cases where another instance is already active. The Makefile has been significantly updated to orchestrate the entire test flow, including setting up the database, starting/stopping the broker, and running unit and integration tests separately.
51 lines
2.0 KiB
PL/PgSQL
51 lines
2.0 KiB
PL/PgSQL
-- broker_schedule table
|
|
-- Stores scheduled jobs (cron-like functionality)
|
|
|
|
CREATE TABLE IF NOT EXISTS broker_schedule (
|
|
id_broker_schedule BIGSERIAL PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL UNIQUE,
|
|
cron_expr VARCHAR(100) NOT NULL,
|
|
enabled BOOLEAN NOT NULL DEFAULT true,
|
|
job_name VARCHAR(255) NOT NULL,
|
|
job_priority INTEGER NOT NULL DEFAULT 0,
|
|
job_queue INTEGER NOT NULL DEFAULT 1,
|
|
job_language VARCHAR(50) NOT NULL DEFAULT 'sql',
|
|
execute_str TEXT NOT NULL,
|
|
run_as VARCHAR(100),
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
last_run_at TIMESTAMP WITH TIME ZONE,
|
|
next_run_at TIMESTAMP WITH TIME ZONE,
|
|
|
|
CONSTRAINT broker_schedule_job_queue_check CHECK (job_queue > 0)
|
|
);
|
|
|
|
-- Indexes
|
|
CREATE INDEX IF NOT EXISTS idx_broker_schedule_enabled ON broker_schedule(enabled);
|
|
CREATE INDEX IF NOT EXISTS idx_broker_schedule_next_run ON broker_schedule(next_run_at) WHERE enabled = true;
|
|
CREATE INDEX IF NOT EXISTS idx_broker_schedule_name ON broker_schedule(name);
|
|
|
|
-- Comments
|
|
COMMENT ON TABLE broker_schedule IS 'Scheduled jobs (cron-like functionality)';
|
|
COMMENT ON COLUMN broker_schedule.name IS 'Unique name for the schedule';
|
|
COMMENT ON COLUMN broker_schedule.cron_expr IS 'Cron expression for scheduling';
|
|
COMMENT ON COLUMN broker_schedule.enabled IS 'Whether the schedule is active';
|
|
COMMENT ON COLUMN broker_schedule.job_name IS 'Name of the job to create';
|
|
COMMENT ON COLUMN broker_schedule.execute_str IS 'SQL or code to execute';
|
|
COMMENT ON COLUMN broker_schedule.last_run_at IS 'Last time the job was executed';
|
|
COMMENT ON COLUMN broker_schedule.next_run_at IS 'Next scheduled execution time';
|
|
|
|
-- Trigger to update updated_at
|
|
CREATE OR REPLACE FUNCTION tf_broker_schedule_update_timestamp()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
NEW.updated_at = NOW();
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
CREATE TRIGGER t_broker_schedule_updated_at
|
|
BEFORE UPDATE ON broker_schedule
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION tf_broker_schedule_update_timestamp();
|