Mirth Connect - Channel Scheduler

Summary:

Long story short I needed a better scheduler. Mirth Connect channels have the ability to be scheduled to run on a timed bases; however, as I have learned if I have over 900 channels on a single server that are all scheduled to run at different times, it becomes a nightmare trying to spread out the schedules so they don’t overwhelm an HDH, Results, or email and sftp server. Allowing single channel to control the scheduling of many channels provides a quick way to lookup what is scheduled to run and when. You will find this schedule channel very time tested and proven and used along with many of my solutions. It also give you a triggering source to build your channel on, which in Mirth Connect is always the best case.


Installation:

  • To Download this solution, click on the 3 dots (…) in the upper right corner and select attached files.
  • Install the channels to Mirth Connect
  • Create the scheduling table that will store all the scheduled tasks.
CREATE SEQUENCE IF NOT EXISTS util_schedule_id_seq INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;CREATE TABLE IF NOT EXISTS util_schedule ( id integer NOT NULL DEFAULT nextval('util_schedule_id_seq'::regclass), server_id character varying(36) NOT NULL, util_name character varying(40), util_desc character varying(255), run_date timestamp without time zone, run_adjust_count character varying(10), run_adjust_interval character varying(20), run_days character varying(40), run_start character varying(6), run_stop character varying(6), status boolean NOT NULL DEFAULT true, channel_id character varying(36), a character varying(255), b character varying(255), c character varying(255), d character varying(255), e character varying(255), f character varying(255), g character varying(255), h character varying(255), CONSTRAINT util_schedule_pkey PRIMARY KEY (id) )

  • Adjust the source database variables in both the source db script and source post process db script for channel Utility Scheduler.

  • Save and deploy channel Utility Scheduler

  • Adjust the source side database variables in the source transformer for channel Populate Scheduler.

  • Save and deploy channel Populate Scheduler

  • Create a new scheduled task through channel Populate Scheduler

Note: util_name is the entry key Note: setting util_desc to "DELETE" will remove the entry Note: channel_id is the id for the channel this packet will be sent to Note: a-h are any startup or trigger variables you wish to send to channel_id [ { "server_id" : "e57e0757-5fad-409f-985f-cfa0d0b5c3d8", "util_name" : "Backup SB", "util_desc" : "Backup Sandbox Channels and Groups", "run_date" : "2022-05-01 00:30:00", "run_adjust_count" : "1", "run_adjust_interval" : "day", "run_days" : "sun,mon,tue,wed,thu,fri,sat", "run_start" : "", "run_stop" : "", "status" : "true", "channel_id" : "b4d864fb-6b70-4683-9118-0a54d0d0c69b", "a" : "https://integrations-sandbox.dev.mirthcorp.com:8443/api", "b" : "username", "c" : "password", "d" : "", "e" : "", "f" : "", "g" : "", "h" : "" } ]

Overview of Operations

There is a control table 'util_schedule' (details below) kept either in a local or centralized database. The overall process is pretty simple, every minute the current datetime is compared to the run_date of the entries in the table, if there is a match then all returned values are looped through and an XML triggering message is sent to the channel registered in channel_id of the table. Then the value in run_date is adjusted forward by the values contained in run_adjust_count and run_adjust_interval, together they make something like the following.

The scheduler channel queries the 'util_schedule' table every minute to compare the current whole minute to the next run times whole minutes.

SELECT id AS report_schedule_id, run_date AS report_schedule_run_date, run_adjust_count, run_adjust_interval, channel_id, a, b, c, d, e, f, g, h FROM util_schedule where run_date <= date_trunc('minute', LOCALTIMESTAMP) and status = true

If there is a match, then a record like the following is returned to the channel and a copy forwarded to the channel noted in field 'channel_id'. The values of fields (a-h) are used as triggers or initiating values for the receiving channel.

<result> <schedule_id>2</schedule_id> <server_id>e57e0757-5fad-409f-985f-cfa0d0b5c3d8</server_id> <util_name>Backup SB</util_name> <util_desc>Backup Sandbox Channels and Groups</util_desc> <current_run_time>0030</current_run_time> <run_date>2022-05-01 00:30:00.0</run_date> <run_adjust_count>1</run_adjust_count> <run_adjust_interval>day</run_adjust_interval> <channel_id>d3514496-15f8-48a2-8d75-4be886675c03</channel_id> <run_days>sun,mon,tue,wed,thu,fri,sat</run_days> <run_start/> <run_stop/> <a>https://integrations-sandbox.dev.mirthcorp.com:8443/api</a> <b>user</b> <c>pass</c> <d/> <e/> <f/> <g/> <h/> </result>


Valid 'run_adjust_interval' field values include:

  • minute

  • hour

  • day

  • week

  • month

  • quarter

  • year

  • decade

  • century

  • millennium

  • Note: yes, you can set the interval to 10 millennium, looks funny but it can be done.

See date_trunc function documentation

update util_schedule set run_date = date_trunc('minute', LOCALTIMESTAMP) + interval '1 month' where id = ?

Note: if you download the solution, you will find 2 channels. 1 channel is the scheduler and 1 channel add and updates the

Note: you can find this solution used as part of the following solutions:














Comments