Skip to content

Commit

Permalink
Uppercase all the keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
ream88 committed Jun 24, 2016
1 parent 7838bab commit 85c497b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/queue_classic/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ def lock

def unlock(id)
QC.log_yield(:measure => 'queue.unlock') do
s = "UPDATE #{QC.table_name} set locked_at = null where id = $1"
s = "UPDATE #{QC.table_name} SET locked_at = NULL WHERE id = $1"
conn_adapter.execute(s, id)
end
end

def delete(id)
QC.log_yield(:measure => 'queue.delete') do
conn_adapter.execute("DELETE FROM #{QC.table_name} where id = $1", id)
conn_adapter.execute("DELETE FROM #{QC.table_name} WHERE id = $1", id)
end
end

Expand Down
25 changes: 12 additions & 13 deletions sql/create_table.sql
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
do $$ begin
DO $$ BEGIN

CREATE TABLE queue_classic_jobs (
id bigserial PRIMARY KEY,
q_name text not null check (length(q_name) > 0),
method text not null check (length(method) > 0),
args text not null,
q_name text NOT NULL CHECK (length(q_name) > 0),
method text NOT NULL CHECK (length(method) > 0),
args text NOT NULL,
locked_at timestamptz,
locked_by integer,
created_at timestamptz default now(),
scheduled_at timestamptz default now()
created_at timestamptz DEFAULT now(),
scheduled_at timestamptz DEFAULT now()
);

-- If jsonb type is available, use it for the args column
if exists (select 1 from pg_type where typname = 'jsonb') then
alter table queue_classic_jobs alter column args type jsonb using args::jsonb;
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'jsonb') THEN
ALTER TABLE queue_classic_jobs ALTER COLUMN args TYPE jsonb USING args::jsonb;
-- Otherwise, use json type for the args column if available
elsif exists (select 1 from pg_type where typname = 'json') then
alter table queue_classic_jobs alter column args type json using args::json;
end if;
ELSIF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'json') THEN
ALTER TABLE queue_classic_jobs ALTER COLUMN args TYPE json USING args::json;
END IF;

end $$ language plpgsql;
END $$ LANGUAGE plpgsql;

CREATE INDEX idx_qc_on_name_only_unlocked ON queue_classic_jobs (q_name, id) WHERE locked_at IS NULL;
CREATE INDEX idx_qc_on_scheduled_at_only_unlocked ON queue_classic_jobs (scheduled_at, id) WHERE locked_at IS NULL;

24 changes: 9 additions & 15 deletions sql/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,17 @@ BEGIN
USING unlocked;

RETURN;
END;
$$ LANGUAGE plpgsql;
END $$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION lock_head(tname varchar)
RETURNS SETOF queue_classic_jobs AS $$
BEGIN
CREATE OR REPLACE FUNCTION lock_head(tname varchar) RETURNS SETOF queue_classic_jobs AS $$ BEGIN
RETURN QUERY EXECUTE 'SELECT * FROM lock_head($1,10)' USING tname;
END;
$$ LANGUAGE plpgsql;
END $$ LANGUAGE plpgsql;

-- queue_classic_notify function and trigger
create function queue_classic_notify() returns trigger as $$ begin
perform pg_notify(new.q_name, '');
return null;
end $$ language plpgsql;
CREATE FUNCTION queue_classic_notify() RETURNS TRIGGER AS $$ BEGIN
perform pg_notify(new.q_name, ''); RETURN NULL;
END $$ LANGUAGE plpgsql;

create trigger queue_classic_notify
after insert on queue_classic_jobs
for each row
execute procedure queue_classic_notify();
CREATE TRIGGER queue_classic_notify
AFTER INSERT ON queue_classic_jobs FOR EACH ROW
EXECUTE PROCEDURE queue_classic_notify();
2 changes: 1 addition & 1 deletion sql/update_to_3_0_0.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DO $$DECLARE r record;
BEGIN
BEGIN
ALTER TABLE queue_classic_jobs ADD COLUMN created_at timestamptz default now();
ALTER TABLE queue_classic_jobs ADD COLUMN created_at timestamptz DEFAULT now();
EXCEPTION
WHEN duplicate_column THEN RAISE NOTICE 'column created_at already exists in queue_classic_jobs.';
END;
Expand Down
2 changes: 1 addition & 1 deletion sql/update_to_3_1_0.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DO $$DECLARE r record;
BEGIN
BEGIN
ALTER TABLE queue_classic_jobs ADD COLUMN scheduled_at timestamptz default now();
ALTER TABLE queue_classic_jobs ADD COLUMN scheduled_at timestamptz DEFAULT now();
CREATE INDEX idx_qc_on_scheduled_at_only_unlocked ON queue_classic_jobs (scheduled_at, id) WHERE locked_at IS NULL;
EXCEPTION
WHEN duplicate_column THEN RAISE NOTICE 'column scheduled_at already exists in queue_classic_jobs.';
Expand Down
2 changes: 1 addition & 1 deletion test/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_worker_uses_one_conn
worker.work
assert_equal(
1,
QC.default_conn_adapter.execute("SELECT count(*) from pg_stat_activity where datname = current_database()")["count"].to_i,
QC.default_conn_adapter.execute("SELECT count(*) from pg_stat_activity WHERE datname = current_database()")["count"].to_i,
"Multiple connections found -- are there open connections to #{ QC.default_conn_adapter.send(:db_url) } in other terminals?"
)
end
Expand Down

0 comments on commit 85c497b

Please sign in to comment.