Python – Inserts the startup process from the mysql line

Inserts the startup process from the mysql line… here is a solution to the problem.

Inserts the startup process from the mysql line

I need to start a server-side process from mysql row insertion. I would appreciate some feedback/suggestions. So far, I can think of three options:

First (least appealing): My initial understanding is that I can write a kind of “custom trigger” in C that triggers row insertion. In addition to having to update my C skills, this requires (custom?) Recompile MySQl … Oops!

Second (and slightly more attractive): I can schedule the cron task server side of a program I write that periodically queries the table for new rows. This has the advantage of being database and language independent. The problem is that I suffered a delay in the cron schedule.

Third (my leading option): I can write a multithreaded program that will query the table for changes on a single thread, spawning new threads as needed to handle newly inserted rows. This has all the benefits of option 2 with less latency.

I’ll also mention that I tend to use Python for this task, as Ease of Access System (Linux) commands along with some internal perl scripts would be very useful.

I would appreciate any feedback/suggestions

Thanks in advance.

Solution

Write an insert trigger that copies the inserted rows to the secondary table. Use an external application/cronjob to periodically poll the rows of the helper table; If there are any rows in the table, delete them and process them (or set the Processing Start flag to be deleted from the secondary table only after successful processing).

This is very effective for medium to low insertion volumes. If you have a large amount of data in your table, some kind of custom trigger written in C may be your only option.

Related Problems and Solutions