timescaledb
timescaledb copied to clipboard
Job#alter_job
I'm just looking around and learning with @intermittentnrg use cases, and it seems a useful scenario:
https://github.com/intermittentnrg/intermittent-importers/blob/d2bb428afc85c05d0e62efd12b53a685b2615c11/app/models/generation_unit.rb#L7-L16
def self.enable_compression_policy!
connection.execute <<~SQL
SELECT alter_job((SELECT job_id FROM timescaledb_information.jobs WHERE proc_name='policy_compression' AND hypertable_name = '#{self.table_name}'), scheduled => true);
SQL
end
def self.disable_compression_policy!
connection.execute <<~SQL
SELECT alter_job((SELECT job_id FROM timescaledb_information.jobs WHERE proc_name='policy_compression' AND hypertable_name = '#{self.table_name}'), scheduled => false);
SQL
end
Which can also be translated as:
def self.enable_compression_policy!
self.hypertable.jobs.compression.select("job_id").each(&:enable!)
end
The method enable! can be implemented directly from the Job model, and we can have a few scenarios like:
Timescaledb.alter_job(job_id, **args)
Job.find(job_id).alter_job(**args)
Then, on the job_level we can have:
def enable!
alter_job(scheduled: true)
end
def disable!
alter_job(scheduled: false)
end
Thanks. I sometimes use this during bulk-ingest where I decompress chunks. Sometimes I forget to use #enable_compression_policy! as it's easy to use SQL.
I have wondered if timescaledb-ruby has API to do this better. Will be great feature.