Module: QC::Queries
Instance Method Summary collapse
-
#job_count(q_name, method, args) ⇒ Object
TODO: Once PostgreSQL supports JSON comparison, use it.
- #job_exists?(q_name, method, args) ⇒ Boolean
Instance Method Details
#job_count(q_name, method, args) ⇒ Object
TODO: Once PostgreSQL supports JSON comparison, use it. But older versions should be supported too (at least >= 9.0).
9 10 11 12 13 |
# File 'lib/qc-additions/queries.rb', line 9 def job_count(q_name, method, args) s = "SELECT COUNT(*) FROM #{TABLE_NAME} WHERE q_name = $1 AND method = $2 AND args::text = $3 AND locked_at IS NULL" r = Conn.execute(s, q_name, method, JSON.dump(args)) r["count"].to_i end |
#job_exists?(q_name, method, args) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/qc-additions/queries.rb', line 15 def job_exists?(q_name, method, args) s = "SELECT 1 AS one FROM #{TABLE_NAME} WHERE q_name = $1 AND method = $2 AND args::text = $3 AND locked_at IS NULL LIMIT 1" r = Conn.execute(s, q_name, method, JSON.dump(args)) !r.nil? end |