stampeded 0.3.1-x86_64-linux-gnu → 0.4.0-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c3888a2ca7ea95040578b4baf9a706d40c648ff282026767e3f219e857cdcf8
4
- data.tar.gz: c3f6439b9e13d247640531a2c91a65d0daba48c1c05a18a3bc4d647cf079fc6b
3
+ metadata.gz: cad7f788cd761495c62f13f696e9a8b6a278fe20cddaf2973deed5fc58e1fb1f
4
+ data.tar.gz: 28788406522070a1ed14f54d8b855e26c7c3c0501c4b69bf6c4466d66f575807
5
5
  SHA512:
6
- metadata.gz: 0f04b0d2a233b276ddaee6303c621d838cc3483951c87c8723fced0bf6efc08530fcc3c3c4f6f0d0f74b8684b3f8e10d3b4596f35e698d5f835dbb562059276d
7
- data.tar.gz: 6eebb4678996da06029c262ac19c3e76e6b0d7533711ec6d89ec4101c13bfb4ef25a1e56a949e4ae03487842387b877457ff24b54c75cb7a7dc642e4228f61ff
6
+ metadata.gz: 47083a221b84efec03e9693cd4cc543307c9c59f35aad9772a8d43b8de48c99fb31b0a770e5ee178ba693c2505b1afba9f0a30a08018528fb51a2d0f46ee9d1e
7
+ data.tar.gz: bb24cac65641ca47c82780535a3325bfab125306a7d14a9ed0536d0bcabbbe77c93c76aa97335fea0820a67a8be71ffc35bd971776d57034fcdd7035432e4ede
data/README.md CHANGED
@@ -25,6 +25,14 @@ scheduler, reaper, pruner, expirer, health checks, HTTP API and dashboard. It
25
25
  never runs a job itself. Without the daemon, jobs still run, but there is no
26
26
  cron, no recovery of jobs from dead workers, no retention and no dashboard.
27
27
 
28
+ The daemon gets the database URL through its environment, never its command
29
+ line. Extra flags go in `STAMPEDED_ARGS`, which `ps` shows to everyone on the
30
+ host, so the dashboard token goes in `STAMPEDED_DASHBOARD_TOKEN` instead:
31
+
32
+ ```bash
33
+ STAMPEDED_DASHBOARD_TOKEN=... STAMPEDED_ARGS="--http 127.0.0.1:7878" bin/rails stampeded:daemon
34
+ ```
35
+
28
36
  ## Transactional enqueue
29
37
 
30
38
  ```ruby
@@ -44,8 +44,9 @@ module Stampeded
44
44
  false
45
45
  end
46
46
 
47
- def exec!(*args)
48
- Kernel.exec(executable, *args)
47
+ def exec!(*args, env: {})
48
+ path = executable
49
+ Kernel.exec(env, [path, path], *args)
49
50
  end
50
51
  end
51
52
  end
@@ -9,7 +9,7 @@ module Stampeded
9
9
  def root
10
10
  candidates = [
11
11
  File.expand_path("../../schema", __dir__),
12
- File.expand_path("../../../schema", __dir__)
12
+ File.expand_path("../../../crates/stampeded/schema", __dir__)
13
13
  ]
14
14
  candidates.find { |d| File.directory?(d) } ||
15
15
  raise(Error, "cannot find schema/*.sql (looked in #{candidates.join(", ")})")
@@ -39,7 +39,8 @@ module Stampeded
39
39
  c.exec(<<~SQL)
40
40
  DROP TABLE IF EXISTS stampeded_cron_occurrences, stampeded_schedules,
41
41
  stampeded_queue_policies, stampeded_queue_counts,
42
- stampeded_jobs, stampeded_workers CASCADE;
42
+ stampeded_jobs, stampeded_workers,
43
+ stampeded_schema CASCADE;
43
44
  DO $$
44
45
  DECLARE r record;
45
46
  BEGIN
@@ -22,11 +22,11 @@ namespace :stampeded do
22
22
  worker.run
23
23
  end
24
24
 
25
- desc "Run the daemon (scheduler, reaper, pruner, dashboard). Not the worker."
25
+ desc "Run the daemon (scheduler, reaper, pruner, dashboard). Not the worker. Upgrades the schema first."
26
26
  task daemon: :environment do
27
27
  require "stampeded/daemon"
28
- args = ["--database-url", Stampeded.database_url_for_daemon, "--no-worker"]
29
- args += ENV["STAMPEDED_ARGS"].to_s.split
30
- Stampeded::Daemon.exec!(*args)
28
+ # --migrate is safe on every start: it upgrades an older schema in place.
29
+ args = ["--no-worker", "--migrate", *ENV["STAMPEDED_ARGS"].to_s.split]
30
+ Stampeded::Daemon.exec!(*args, env: { "STAMPEDED_DATABASE_URL" => Stampeded.database_url_for_daemon })
31
31
  end
32
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stampeded
4
- VERSION = "0.3.1" # x-release-please-version
4
+ VERSION = "0.4.0" # x-release-please-version
5
5
  end
data/lib/stampeded.rb CHANGED
@@ -50,9 +50,14 @@ module Stampeded
50
50
  params = Connection.connection_params
51
51
  return params if params.is_a?(String)
52
52
 
53
- user = [params[:user], params[:password]].compact.join(":")
54
- host = [params[:host], params[:port]].compact.join(":")
55
- "postgres://#{user}#{"@" unless user.empty?}#{host}/#{params[:dbname]}"
53
+ userinfo = URI.encode_uri_component(params[:user].to_s)
54
+ userinfo += ":#{URI.encode_uri_component(params[:password].to_s)}" if params[:password]
55
+ host = params[:host].to_s
56
+ host = host.include?(":") ? "[#{host}]" : URI.encode_uri_component(host)
57
+ host += ":#{params[:port]}" if params[:port]
58
+ url = "postgres://#{userinfo}#{"@" unless userinfo.empty?}#{host}/#{URI.encode_uri_component(params[:dbname].to_s)}"
59
+ tls = params.slice(*Connection::TLS_KEYS).map { |key, value| "#{key}=#{URI.encode_uri_component(value.to_s)}" }
60
+ tls.empty? ? url : "#{url}?#{tls.join("&")}"
56
61
  end
57
62
 
58
63
  def create_queue(name)
Binary file
data/libexec/stampeded CHANGED
Binary file
data/schema/schema.sql CHANGED
@@ -65,15 +65,20 @@ CREATE TABLE stampeded_jobs (
65
65
  dedup_period text CHECK (dedup_period IN
66
66
  ('minute','hour','day','week','month')),
67
67
 
68
+ -- Scope, period and bucket: buckets of two periods start together (an
69
+ -- hour and its day at midnight UTC), so the period keeps them apart.
70
+ -- Joined as bytea with a raw zero byte: no `text` value can ever decode
71
+ -- to one (chr(0) itself is refused), so a crafted dedup_scope can never
72
+ -- forge the separator and so never forge another row's key.
68
73
  dedup_key bytea GENERATED ALWAYS AS (
69
- sha256((
70
- dedup_scope || coalesce(
71
- ':' || extract(
74
+ sha256(
75
+ dedup_scope::bytea || '\x00'::bytea || coalesce(
76
+ dedup_period::bytea || '\x00'::bytea || extract(
72
77
  epoch FROM (date_trunc(dedup_period, inserted_at, 'UTC') - to_timestamp(0))
73
- )::bigint::text,
74
- ''
78
+ )::bigint::text::bytea,
79
+ ''::bytea
75
80
  )
76
- )::bytea)
81
+ )
77
82
  ) STORED,
78
83
 
79
84
  failure_kind text,
@@ -1047,3 +1052,13 @@ CREATE TABLE stampeded_queue_policies (
1047
1052
  created_at timestamptz NOT NULL DEFAULT now(),
1048
1053
  updated_at timestamptz NOT NULL DEFAULT now()
1049
1054
  );
1055
+
1056
+ -- Which schema this database holds, one row: `stampeded::schema::migrate`
1057
+ -- upgrades from it and refuses one newer than itself. Raised by each upgrade.
1058
+ CREATE TABLE stampeded_schema (
1059
+ version integer NOT NULL CHECK (version > 0),
1060
+ changed_at timestamptz NOT NULL DEFAULT now()
1061
+ );
1062
+ CREATE UNIQUE INDEX stampeded_schema_one_row ON stampeded_schema ((true));
1063
+ -- Must match schema::VERSION.
1064
+ INSERT INTO stampeded_schema (version) VALUES (3);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stampeded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Abdelkader Boudih