Class: PgCron::Job Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A scheduled job as it exists in cron.job, and how it is written back into db/schema.rb.
F(x)'s equivalent is Fx::Function, whose identity is a signature — name plus argument types, because Postgres allows overloads. A cron job has none: pg_cron keys on jobname, so the name is the identity and scheduling over an existing name replaces it.
Instance Attribute Summary collapse
- #active ⇒ Object readonly private
- #command ⇒ Object readonly private
- #database ⇒ Object readonly private
- #name ⇒ Object readonly private
- #schedule ⇒ Object readonly private
- #username ⇒ Object readonly private
Instance Method Summary collapse
- #<=>(other) ⇒ Object private
- #==(other) ⇒ Object private
-
#definition ⇒ Object
private
Rebuilt as a cron.schedule() call rather than dumped verbatim: pg_cron stores the PARTS (jobname, schedule, command) in cron.job and keeps no record of the statement that created them, so there is nothing to quote back.
-
#initialize(row) ⇒ Job
constructor
private
A new instance of Job.
- #to_schema ⇒ Object private
Constructor Details
#initialize(row) ⇒ Job
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Job.
18 19 20 21 22 23 24 25 |
# File 'lib/pg_cron/job.rb', line 18 def initialize(row) @name = row.fetch("jobname") @schedule = row.fetch("schedule") @command = row.fetch("command") @database = row.fetch("database", nil) @username = row.fetch("username", nil) @active = row.fetch("active", nil) end |
Instance Attribute Details
#active ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def active @active end |
#command ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def command @command end |
#database ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def database @database end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def name @name end |
#schedule ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def schedule @schedule end |
#username ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/pg_cron/job.rb', line 16 def username @username end |
Instance Method Details
#<=>(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/pg_cron/job.rb', line 27 def <=>(other) name <=> other.name end |
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/pg_cron/job.rb', line 31 def ==(other) name == other.name && definition == other.definition end |
#definition ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Rebuilt as a cron.schedule() call rather than dumped verbatim: pg_cron stores the PARTS (jobname, schedule, command) in cron.job and keeps no record of the statement that created them, so there is nothing to quote back. This is the same reason F(x) can use pg_get_functiondef and this cannot.
The command is dollar-quoted because any non-trivial SQL command contains quotes of its own. $job$ rather than $$ so a command that itself uses $$ (a plpgsql body, say) still nests correctly.
44 45 46 47 48 49 50 51 52 |
# File 'lib/pg_cron/job.rb', line 44 def definition <<~SQL SELECT cron.schedule( #{quote(name)}, #{quote(schedule)}, $job$#{command}$job$ ); SQL end |
#to_schema ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 58 59 60 |
# File 'lib/pg_cron/job.rb', line 54 def to_schema <<~SCHEMA.indent(2) create_cron_job :#{name}, sql_definition: <<-'SQL' #{definition.indent(4).rstrip} SQL SCHEMA end |