Database table design for scheduling tasks

后端 未结 5 1324
悲哀的现实
悲哀的现实 2020-12-08 05:09

I want to be able to create schedules that can be executed based on a fixed date, repeated daily, repeated on a particular day of the week, repeated on a particular month of

5条回答
  •  旧巷少年郎
    2020-12-08 05:53

    You could start with a simple table with the following generic schema for storing schedules (PostgreSQL). Consider every instance of a schedule run termed as a "job".

    CREATE TABLE Schedule (
        id SERIAL UNIQUE,                      -- unique identifier for the job
        name varchar(64) NOT NULL,             -- human readable name for the job
        description text,                      -- details about the job
        schedule varchar(64) NOT NULL,         -- valid CRON expression for the job schedule
        handler varchar(64) NOT NULL,          -- string representing handler for the job
        args text NOT NULL,                    -- arguments for the job handler
        enabled boolean NOT NULL DEFAULT TRUE, -- whether the job should be run
        created_at timestamp NOT NULL,         -- when was the job created
        updated_at timestamp NOT NULL,         -- when was the job updated
        start_date timestamp,                  -- job should not run until this time
        end_date timestamp,                    -- job should not run after this time
        last_triggered_at timestamp,           -- when was the job last triggered
        meta json                              -- additional metadata for the job 
    );
    

提交回复
热议问题