Class: Parse::JobSchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/model/classes/job_schedule.rb

Overview

Note:

This collection is consumed by external scheduling tooling, not by Parse Server itself. #params is stored as a JSON string (not an Object) per the canonical Parse Server schema; use #parsed_params to decode. _JobSchedule is hardcoded master-key-only at Parse Server's REST layer (SharedRest.js) — CLP changes via Object.set_clp have no effect.

This class represents the data and columns contained in the standard Parse _JobSchedule collection. Rows here define recurring runs for background jobs registered via +Parse.Cloud.job(...)+. The collection is populated by the Parse Dashboard's "Schedule a Job" UI and consumed by Parse Server's scheduler.

The default schema for JobSchedule is as follows:

class Parse::JobSchedule < Parse::Object # See Parse::Object for inherited properties...

 property :job_name
 property :description
 property :params              # JSON-encoded string of params (server stores as String)
 property :start_after         # ISO 8601 timestamp string for first run
 property :days_of_week, :array
 property :time_of_day         # "HH:MM:SS"
 property :last_run, :integer  # epoch seconds of the previous run
 property :repeat_minutes, :integer

end

Defining and scheduling a job

The job itself is registered in Parse Server's Cloud Code (server-side JavaScript). See JobStatus for the +Parse.Cloud.job(...)+ registration example.

Schedules are normally created through the Parse Dashboard "Jobs" tab, which writes the _JobSchedule row for you. The dashboard exposes:

_JobSchedule is a metadata collection: it stores schedule definitions but Parse Server itself does not auto-trigger jobs from these rows. The actual dispatch is performed by external tooling (e.g. +parse-server-scheduler+, dashboard-driven cron wrappers, or a sidecar process) which reads _JobSchedule and fires +POST /parse/jobs/+ at the appropriate times. Run status rows then appear in JobStatus.

Reading a schedule from Ruby

schedule = Parse::JobSchedule.for_job("nightlyCleanup").first schedule.parsed_params # => { "dryRun" => false } (decoded from params) schedule.time_of_day # => "03:00:00" schedule.days_of_week # => ["mon","tue","wed","thu","fri"]

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#days_of_weekArray

Array of day-of-week identifiers indicating which days the job is eligible to run. The exact token set (e.g. +"mon"+/+"tue"+/... vs. +0+..+6+) is determined by the scheduler tooling that writes the row; the Parse Server schema only requires that the column hold an array.

Returns:



109
# File 'lib/parse/model/classes/job_schedule.rb', line 109

property :days_of_week, :array

#descriptionString

Free-form description of this scheduled job, as entered in the dashboard.

Returns:



88
# File 'lib/parse/model/classes/job_schedule.rb', line 88

property :description

#job_nameString

The registered job name to invoke on each run.

Returns:



82
# File 'lib/parse/model/classes/job_schedule.rb', line 82

property :job_name

#last_runInteger

Raw Number timestamp recording the previous run. The unit is scheduler-defined — most external schedulers write +Date.now()+ milliseconds, but the canonical Parse Server schema only declares +Number+ and does not pin a unit. Treat values written by one scheduler as opaque to others.

Returns:

  • (Integer)


124
# File 'lib/parse/model/classes/job_schedule.rb', line 124

property :last_run, :integer

#paramsString

JSON-encoded string of parameters to pass to the job. Stored as a String in the canonical Parse Server schema to avoid the nested-key character restrictions that apply to Object columns.

Returns:



95
# File 'lib/parse/model/classes/job_schedule.rb', line 95

property :params

#repeat_minutesInteger

Interval in minutes between runs, when the schedule is interval-based rather than time-of-day-based.

Returns:

  • (Integer)


130
# File 'lib/parse/model/classes/job_schedule.rb', line 130

property :repeat_minutes, :integer

#start_afterString

ISO 8601 timestamp string indicating the earliest time the first scheduled run may fire.

Returns:



101
# File 'lib/parse/model/classes/job_schedule.rb', line 101

property :start_after

#time_of_dayString

"HH:MM:SS" string indicating the time of day at which the job should run on each eligible day.

Returns:



115
# File 'lib/parse/model/classes/job_schedule.rb', line 115

property :time_of_day

Class Method Details

.for_job(name) ⇒ Parse::Query

Query scope for schedules belonging to a specific job by name.

Parameters:

Returns:



136
137
138
# File 'lib/parse/model/classes/job_schedule.rb', line 136

def for_job(name)
  query(job_name: name.to_s)
end

Instance Method Details

#parsed_paramsHash?

Decoded form of #params, which is stored on the wire as a JSON string per the canonical Parse Server schema. Returns the parsed Hash, or nil if params is blank, or nil if the stored string is not valid JSON (Parse Dashboard occasionally writes a non-JSON description string here for ad-hoc schedules — we swallow the parse error rather than crash the caller).

Returns:



148
149
150
151
152
153
# File 'lib/parse/model/classes/job_schedule.rb', line 148

def parsed_params
  return nil if params.blank?
  JSON.parse(params)
rescue JSON::ParserError
  nil
end