This is a story of struggle and friendship. We set to download the entire Instagram and came pretty close to achieve our goal. Along the way, we developed a fast and reliable stateful queue system based on Postgres and today you can easily integrate task delegation in your software architecture.
https://youtu.be/g8P_w5dyW3c
53. # How much cumulated work?
SELECT COUNT (*) FROM tasks
WHERE status = 1;
# How much planned word?
SELECT COUNT (*) FROM tasks
WHERE status = 0;
# Other metrics…
54.
55. CREATE TABLE metrics (
metric CHARACTER … NOT NULL,
value INTEGER
);
CREATE TABLE metrics_logs (
ctime TIMESTAMP,
metric CHARACTER … NOT NULL,
increment INTEGER
);
58. FOR VAR_r IN
SELECT
DISTINCT ON (metric),
metric, increment
FROM metrics_logs
ORDER BY ctime ASC
LOOP
…
END LOOP;
59. SELECT SUM(increment) INTO VAR_sum
FROM metrics_logs
WHERE metric = VAR_r.metric;
UPDATE metrics AS t
SET value = t.value + VAR_sum
WHERE metric = VAR_r.metric;