Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job#alter_job #97

Open
jonatas opened this issue Jan 15, 2025 · 0 comments
Open

Job#alter_job #97

jonatas opened this issue Jan 15, 2025 · 0 comments

Comments

@jonatas
Copy link
Collaborator

jonatas commented Jan 15, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant