Upgrading Rocket Job
Contents
Release notes for every version are published in the GitHub Releases. This page collects the upgrade steps that need code or data changes when moving between versions.
Upgrade one version at a time
Upgrade through each version in turn, such as from v7.0 to v7.1, to v7.2, and then to v8, rather than from v7.0 straight to v8. After each upgrade, fix every deprecation warning that it reports before you upgrade to the next version:
- Upgrade to the next version, following its section below.
- Run your tests with Ruby’s deprecation warnings on, see Find the deprecated options that you use, and change what each warning reports, until none are left.
- Change the saved documents that still hold a deprecated option, such as Dirmon entries, scheduled
jobs and
UploadFileJobs, since reading one back reports no warning, see Propose the schema of each category. - Deploy, and only then upgrade to the next version.
A minor release, such as v7.1, adds what replaces the options that the next major release removes, and deprecates them, so that each change can be made, and tested, while the old option still works. The next major release, such as v8, then removes what was deprecated, so code that still uses it stops working.
Upgrading to v7.2
v7.2 prepares an application for v8. Upgrade to v7.1 first, see
Upgrading to v7.1. v7.2 reports a deprecation warning for each of the other
options that v8 removes, and for each upload of a query that v8 uploads differently, see
Uploading a query, and adds what replaces them. The deprecated options keep
working. Its warnings are reported as v7.1 reports its own, see
Find the deprecated options that you use, and
RocketJob::SchemaProposal lists the saved documents that still hold an option that v8 removes, see
Propose the schema of each category.
Replace the :array upload mode
An input category’s mode: :array, and the stream_mode: :array of upload, are deprecated, and
removed in v8. A category with a schema cannot use them. Use the default :line mode, in which each
worker parses its lines, and leave out stream_mode::
# Before (deprecated)
input_category format: :csv, mode: :array
# After
input_category format: :csv
A category without a format does not parse its lines, so stream_mode: :array was what read each
line of a file into an Array. Give such a category the format of its files, or format: :auto to
take it from the file name, so that the workers read each line, and #perform receives a Hash keyed
by the columns of the header row, rather than an Array. stream_mode: :array uploaded the first
line of a file as a record too, so for a file without a header row, also give the category a schema
with "header" => false and a field for each column, in order, see
Replace the column options with a schema: otherwise its
first line is read as the header row.
To also parse every line when the file is uploaded, so that a file with a problem is found before it
is processed, use validate_rows: true, see
Replace the :hash mode and stream_mode.
Replace the :hash mode and stream_mode
An input category’s mode: :hash, and the stream_mode: of upload, are deprecated, and removed in
v8. An input category’s validate_rows: true, and the validate_rows: of upload, replace them: each
line of a file in the category’s format is parsed while the file is uploaded, so that a file with a
line that cannot be read, or with a value that is not valid for its field in the schema, uploads
nothing. The lines are still uploaded as they are, and the workers parse them:
# Before (deprecated)
input_category format: :csv, mode: :hash, schema: "schemas/people.json"
job.upload("people.csv", stream_mode: :hash)
# After
input_category format: :csv, validate_rows: true, schema: "schemas/people.json"
job.upload("people.csv", validate_rows: true)
validate_rowsalso validates the lines of a category without a schema, whichmode: :hashdid not.- A category without a format, which
stream_mode: :hashread a file into Hashes for, gives the categoryformat: :autoinstead, so that the workers read each line into a Hash, in the format of the file name. Leave outstream_mode: :line, which is the default. uploadwith a block does not validate the records that it writes in 7.2, and raises forvalidate_rows: true. v8 also validates the lines that the block writes.- Until it is removed,
stream_mode:decides alone whether a file is validated, over the category’svalidate_rows. So in a category withvalidate_rows: true, replacestream_mode: :linebyvalidate_rows: false, rather than leave it out. - v8 raises
ArgumentErrorwheneverstream_mode:is passed, also asnil, whatever is uploaded, so v7.2 warns for it then too: remove it from every call.stream_mode: niluploads a file as if it were left out. - In a category with a format, 7.2 uploads the lines of a file in
stream_mode: :hash, reading its header row, and parses each one first, asvalidate_rows: truedoes. 7.1 raisedIOStreams::Errors::TypeMismatchfor a file with a header row, such as CSV, without a schema. For a file without a header row, such as JSON, in a category without a schema, the options ofuploadthat describe the columns of a file, such asallowed_columns:, are still accepted, and have no effect there, as in 7.1. - 7.2 raises
ArgumentErrorfor astream_mode:other than:line,:arrayor:hash, such as:hashes, as 7.1 did without a schema. With a schema 7.1 read one as:hash. - v8 reads a job saved with
mode: :hashin a category with a format asvalidate_rows: true, unless itsvalidate_rowsis false. With a schema that is whatmode: :hashdid, so such a job need not change. Without a schemamode: :hashdid not validate the lines, so remove it, rather than replace it, to keep uploading a file with a line that cannot be read. The schema proposals make both changes, in job classes and in saved jobs, Dirmon entries andUploadFileJobs.
Servers running v7.0 or v7.1 cannot read validate_rows, so upgrade every server before giving any
Dirmon entry or UploadFileJob one.
Replace on_first
The on_first: option of upload is deprecated, and removed in v8. Its lambda was called with the
header row of a file, or, for a file without one, such as JSON or fixed width, with the first
record, which was then not uploaded. v8 raises ArgumentError whenever on_first: is passed, also
as nil, whatever is uploaded, so v7.2 warns for it then too: remove it from every call.
Rocket Job reads the header row of a file in a format that has one, such as CSV, itself, so a
lambda that only reads it can be removed. 7.2 also sets its columns in job.input_category.columns,
but do not read them there in place of the lambda: v8 leaves them nil, since each slice holds the
header row of its file. To check the columns of a file, describe them with the category’s schema,
which raises IOStreams::Errors::InvalidHeader during the upload when the header row does not match
its fields:
# Before (deprecated)
job.upload(file_name, on_first: ->(header) { raise "No zip column" unless header.include?("zip") })
# After
input_category format: :csv,
schema: {
"fieldsMatch" => "subset",
"extraColumns" => "keep",
"fields" => [{"name" => "zip"}]
}
"fieldsMatch" => "subset" requires the zip column, in any position, and accepts the other
columns of the file, which "extraColumns" => "keep" keeps in each record. Without fieldsMatch a
schema requires exactly the columns of its fields, in their order. Add "keyType" => "cleansed" to
keep the keys of the other columns cleansed, as without a schema, such as first_name for the column
First Name: without it they are keyed as they are in the file, so record["first_name"] is nil,
without an error.
To leave out the first record of a file without a header row, such as the control record at the start of a fixed width file, upload the file with a block that writes every line but that one:
# Before (deprecated)
job.upload(file_name, on_first: ->(line) { job.control_record = line })
# After
job.upload(file_name: file_name) do |lines|
first = true
IOStreams.path(file_name).encoding("UTF-8").each(:line) do |line|
if first
job.control_record = line
first = false
else
lines << line
end
end
end
The block reads the file itself, as UTF-8 here: without an encoding IOStreams 2.2 reads its lines as
binary, and one with a letter that is not ASCII, such as José, cannot be uploaded. For a file in
another encoding, give the path that one instead, such as
IOStreams.path(file_name).encoding("ISO-8859-1").
Line options of upload
The delimiter:, buffer_size: and embedded_within: options of upload are deprecated, and
removed in v8, which reads the lines of a file itself:
delimiter:IOStreams detects the line endings of a file,\r\nor\n, so remove it. A file whose records are separated by something other than a line ending cannot be uploaded as a file in v8: write its records in the block ofuploadinstead, reading the file with thedelimiter:of IOStreams, which streams it rather than reading the whole file into memory.buffer_size:only tuned how much IOStreams read at a time, so remove it.embedded_within:kept a quoted value that holds line breaks in its line. In v8 the format of the input category, such as CSV, reads such a value, so remove it and give the category its format.
# Before (deprecated)
job.upload(file_name, delimiter: "|")
# After
job.upload do |records|
IOStreams.path(file_name).encoding("UTF-8").each(:line, delimiter: "|") do |record|
records << record
end
end
The block reads the file as UTF-8, since without an encoding IOStreams 2.2 reads its records as binary, see Replace on_first: give the path the encoding of the file.
v7.2 reads a quoted value that holds line breaks in the format of the path that is uploaded, not in
that of the input category. A file whose name gives its format, such as people.csv, has one. An
IO, or a file whose name does not give its format, such as people.txt, has none, so without
embedded_within: v7.2 splits such a value into two records. Give the path its format before
removing embedded_within::
# Before (deprecated)
job.upload(io, embedded_within: '"')
job.upload("people.txt", embedded_within: '"')
# After
job.upload(IOStreams.stream(io).format(:csv))
job.upload(io, file_name: "people.csv")
job.upload(IOStreams.path("people.txt").format(:csv))
Uploading a query
v8 uploads an Active Record relation in one streamed query, read with IOStreams 3.0 rather than
find_each, and builds no models, so that uploading millions of rows does not build a model for
each one. Each value is cast as pluck casts it. The records are the same: the value of one column,
the id by default, or an Array of the values of several columns. Three things change. v7.2 reports
a deprecation warning, at the line that uploads the query, for each one that an upload depends on,
and still uploads the same records as v7.0.
A block raises. v8 raises ArgumentError for a block passed with a query, an Active Record
relation or a Mongoid criteria, since it uploads the values of the columns rather than what a block
returns. Write the records in the block of upload instead, reading the query there:
# Before (deprecated)
job.upload_arel(User.where(country_code: "US")) do |user|
user.email.downcase
end
# After
job.upload do |records|
User.where(country_code: "US").find_each do |user|
records << user.email.downcase
end
end
The block of upload builds a model for each row, as v7 did. For a large table, upload the columns
that perform needs instead, and do the work there:
job.upload(User.where(country_code: "US"), columns: [:email])
def perform(email)
email.downcase
end
Eager loading raises. A relation that uses includes, preload or eager_load raises
ArgumentError in v8, since there are no models to load associations into. To read an association,
write the records in the block of upload, which loads it as v7 did:
# Before (deprecated)
job.upload_arel(User.includes(:company)) do |user|
user.company.name
end
# After
job.upload do |records|
User.includes(:company).find_each do |user|
records << user.company.name
end
end
To upload the rows that have an association, join it, with distinct so that each row is uploaded
once, or use a subquery. Both upload the same ids as v7:
# Before (deprecated)
job.upload(User.includes(:posts).where(posts: {published: true}))
# After
job.upload(User.joins(:posts).where(posts: {published: true}).distinct)
# Or
job.upload(User.where(id: Post.where(published: true).select(:user_id)))
A column is uploaded without its reader. v8 uploads the value that each column holds, as pluck
and read_attribute return it, rather than calling the reader of the model. They differ only where
the model overrides the reader. normalizes, enum, serialize and alias_attribute give the
same value both ways. While deprecation warnings are on, v7.2 compares them for each row until they
differ, and names the model and the column, never the values. To keep the reader’s value, write the
records in the block of upload, which calls it, or apply the reader’s logic in perform:
class User < ActiveRecord::Base
def nickname
super || "none"
end
end
# Before (deprecated), uploads "none" for a user without a nickname
job.upload(User.all, columns: [:nickname])
# After
job.upload do |records|
User.find_each do |user|
records << user.nickname
end
end
v7.2 reports each of these at the line that uploads the query, once for each change, for example:
app/jobs/export_job.rb:12: warning: Rocket Job: User#nickname returns a value other than the one that its column holds, which Rocket Job 8 uploads instead, as pluck returns it, rather than calling the reader: to keep the reader's value, write the records in the block of upload, which can call it, or apply the reader's logic in perform, see https://rocketjob.reidmorrison.com/upgrading.html#upgrading-to-v72
Call upload with a query or a range
upload_arel, upload_mongo_query, upload_integer_range and
upload_integer_range_in_reverse_order, deprecated since v6, report a deprecation warning, since v8
removes them. Call upload with the relation, the criteria or the range instead, which v7 and v8
both accept. A block passed with a query is deprecated too, see Uploading a query:
# Before (deprecated)
job.upload_arel(User.where(country_code: "US"), :zip_code)
job.upload_mongo_query(User.where(state: "FL"), :zip_code)
job.upload_integer_range(1, 1_000_000)
job.upload_integer_range_in_reverse_order(1, 1_000_000)
# After
job.upload(User.where(country_code: "US"), columns: [:zip_code])
job.upload(User.where(state: "FL"), columns: [:zip_code])
job.upload(1..1_000_000)
job.upload(1_000_000..1)
A range is uploaded in the direction that it is written. upload_integer_range(first, last)
uploaded nothing when last was less than first, while upload(first..last) uploads that range
from its last id, so where the bounds are computed, check for that first. A range that excludes its
end, such as 1...100, uploads its end in v7, but not in v8, so write it as 1..99.
The before_code of an OnDemandBatchJob that calls one of them, as its documentation showed,
reports the warning when the job runs, and raises NoMethodError in v8: change it to call upload,
including in the jobs that are already saved, such as a scheduled one, which copies its
before_code to its next run.
A second file in one input category
In v7 the workers read every record of an input category by one header row, the one that its
upload read, see input_category.columns. So in v7.2 a second file uploaded into an input category
with a schema, whose input already holds the records of a first file, uploads nothing when its
header row reads its columns as other fields than the first file’s, or in another order. v7.1 read
the records of both files by the second file’s header row, giving values to the wrong fields:
- A header row that does not match the schema raises
IOStreams::Errors::InvalidHeader, as before. With the defaultfieldsMatch“exact”, which needs every field in its order, a header row either matches the schema, and so reads the same fields in the same order, or raises it. - A header row that matches the schema, but whose columns are other fields, or in another order, such
as with
fieldsMatch“equal”, raisesArgumentError. - A header row that the schema reads the same, such as one that differs only in the case or spaces of a column, or in a column that the schema skips, is uploaded as before.
job.upload("people_1.csv")
job.upload("people_2.csv") # raises when its header row reads other fields
When either raises, the job keeps the records of the first file, and the header row that they are read by.
Upload a file whose header row differs into a job of its own. Without a schema, v7.2 still stores the header row of a second file as a record, and reads its records by the first file’s header row, as v7.0 did, so give such a category a schema, or upload each file into a job of its own. v8 reads the records of each file by its own header row.
Propose the schema of each category
The warnings name the lines of code, but not the saved documents that hold a deprecated option, such
as scheduled jobs, Dirmon entries and UploadFileJobs, since reading one back does not report a
warning. RocketJob::SchemaProposal proposes the schema that replaces the deprecated options of each
category, for both, and changes nothing. Run it from a console of the application, once its job
classes are loaded, such as with Rails.application.eager_load!:
puts RocketJob::SchemaProposal.report
It lists each job class that defines a category with a deprecated option, each saved job that can
still run, and each Dirmon entry and UploadFileJob whose properties hold one, for example:
ImportJob, input category main
Set: allowed_columns: remove, skip_unknown: false
Set schema: {"fieldsMatch" => "partial", "fields" => [{"name" => "first_name"}, {"name" => "zip_code"}], "keyType" => "cleansed"}
Check: A name that 7.0 cleansed from a column with letters that are not ASCII lost them, ...
Each proposal reads the files as the options did in 7.0, which is not always what they say: options
that 7.0 never applied, such as allowed_columns for JSON records, are removed rather than described
in the schema, and the proposal says so. It also says what to check, and when it cannot translate a
category, such as a layout with two columns that have one key, or a job that should finish first: one
that is already running, or a queued job that has uploaded a header row that the schema cannot read,
such as one with two columns that match one field, like a and A, or FirstName and First Name
for a field first_name. Columns that a scheduled job copied from the header row of an earlier
upload are removed, rather than read as the columns of a file without a header row. The proposal also
shows the schema to use instead, should the application have set those columns for a file without a
header row, unless they repeat a name, which a schema cannot hold.
Before applying a proposal, read a recent file of the job with it. #dry_run reads the first records
of a file both ways, and lists what differs, such as a key that is no longer read:
proposal = ImportJob.schema_proposals.first
proposal.dry_run("/data/in/orders_20261020.csv")
# => ["Record 1: keys no longer read: [\"prnom\"]"]
Then apply it by hand: in the job class, replace the deprecated options with the schema, and for a
saved job, Dirmon entry or UploadFileJob, set the same in its category, or its properties. Mission
Control 7.1 shows and sets the schema of a category, in the job and Dirmon entry forms. Its forms
cannot clear format_options or columns, nor edit allowed_columns, required_columns or
header_cleanser, so a proposal that changes one of those cannot be applied there: apply it in the
job class, or from a console. A category that still holds one of them, other than the columns of
an input category, fails validation once it is given a schema. Mission Control 7.0 cannot set a
schema, and saving a Dirmon entry in it rebuilds the entry’s properties without one.
Upgrading to v7.1
v7.1 moves Rocket Job to IOStreams 2.2, which bundle update rocketjob installs. IOStreams 2.2
deprecates what IOStreams 3.0 removes, and reports a deprecation warning wherever the application uses
one of those, see
Upgrading IOStreams to v2.2.
Rocket Job 7.1 no longer uses any of them itself.
An application sets some of them through Rocket Job, rather than on IOStreams: a category’s
format_options, and the options that describe the columns of a file, such as allowed_columns.
IOStreams does not report those that a category passes to it, so Rocket Job reports them instead, and
adds a category’s schema, which replaces them, as IOStreams’ #schema replaces them. The deprecated
options keep working.
A job that does not use a schema reads and writes its files as it did in v7.0, apart from these fixes:
- An upload of a path whose streams were set with
#stream, such asstream(:gz), into a category with a format reads the file, where v7.0 raised or read the wrong text. - Blank lines before the header row of a tabular file are skipped, where v7.0 took the first one as the header row.
- A
format: :autoupload of a JSON or fixed width file keeps its first record, sorecord_countis one more than in v7.0. - A category in the
:arrayor:hashmode reads the header row of a file such as CSV, where v7.0 raised, or failed every slice.
Servers running v7.0 and v7.1 can run together, but upgrade every server before giving any job,
Dirmon entry or UploadFileJob a schema. A v7.0 worker ignores a category’s schema, so it would read
the records of such a job by the header row as it is in the file, with every value as text.
Replace format_options with a schema
A category’s format_options is deprecated, and replaced by its schema, which IOStreams uses for
every tabular format, see Describing a file with a schema. A
fixed width layout becomes a schema with the width of each field:
# Before (deprecated)
input_category format: :fixed,
format_options: {
layout: [
{size: 10, key: "name"},
{size: 5, key: "zip", type: :integer}
]
}
# After
input_category format: :fixed,
schema: {
"fieldsMatch" => "subset",
"fields" => [
{"name" => "name", "type" => "string", "width" => 10, "truncate" => true},
{"name" => "zip", "type" => "integer", "width" => 5}
]
}
Each column of the layout is a field of the schema: its key is the name, its size the
width, and its type the type, with "truncate" => true on a string field, as a layout
truncates a longer value. The table in IOStreams’
Moving a layout to a schema
gives each of them, including fillers and :float. "fieldsMatch" => "subset" makes writing skip
the keys of a record that the layout does not list, as a layout did. Leave it out to raise
IOStreams::Errors::InvalidHeader for such a key instead, so that a misspelled key is not silently
left out.
A schema reads a fixed width file differently from a layout, so check each job as you move it:
- The keys of the records are the names of the fields, which are Strings. A layout with Symbol keys,
such as
key: :name, gave records with Symbol keys, also once a worker read the job back, so add"keyType" => "symbol"to its schema to keep them, or changerecord[:name]torecord["name"]in#perform. - A value that is not of the type of its field, such as letters in an
integerfield, fails its record withIOStreams::Errors::InvalidValue. - The text is read as UTF-8, see Text is read as UTF-8 with a schema.
- The column options, such as
columns, cannot be set with a schema. An input category’scolumnsthat narrowed the records of a layout to some of its keys become the fields of the schema.
A layout cannot be set with a schema, since IOStreams would reject them rather than apply one and ignore the other.
Replace the column options with a schema
The schema also describes the columns of a file, so the options that described them are deprecated:
an input category’s allowed_columns, required_columns, skip_unknown and header_cleanser, and the
columns of a file without a header row, or of the output to write. So are the same options passed
to upload, such as allowed_columns:. See
Matching columns to the fields of a schema
and Filtering output columns.
# Before (deprecated)
input_category format: :csv,
allowed_columns: %w[login last_login name state],
required_columns: %w[login],
skip_unknown: true
output_category format: :csv, columns: %w[login last_login]
# After
input_category format: :csv,
schema: {
"fieldsMatch" => "partial",
"fields" => [
{"name" => "login", "constraints" => {"required" => true}, "allowBlank" => true},
{"name" => "last_login"},
{"name" => "name"},
{"name" => "state"}
]
}
output_category format: :csv,
schema: {
"fieldsMatch" => "subset",
"fields" => [
{"name" => "login"},
{"name" => "last_login"}
]
}
"allowBlank" => true keeps a record whose login is blank, as required_columns did, which only
checked that the file had the column. Leave it out to reject such a record too.
The schema property that replaces each option, and each combination of them:
| Option | With a schema |
|---|---|
header_cleanser: :default, the default |
"keyType" => "cleansed", so that the keys of each record are cleansed, as before. A column that is not a field, which "extraColumns" => "keep" keeps, is keyed the same way. |
allowed_columns |
"fieldsMatch" => "superset", which accepts a file without some of the fields, as allowed_columns does, or "equal" when required_columns lists every allowed column. |
allowed_columns with skip_unknown: true |
"fieldsMatch" => "partial", which accepts a file without some of the fields, as allowed_columns does, or "subset" when required_columns lists every allowed column. |
required_columns with allowed_columns |
"constraints" => {"required" => true} with "allowBlank" => true on each required field, which needs the column but not a value, as required_columns did. Without allowBlank, a blank value raises too. |
required_columns alone |
A field for each of them, with "constraints" => {"required" => true} and "allowBlank" => true, and "fieldsMatch" => "subset" with "extraColumns" => "keep", which keeps the other columns of the file, after the fields, as required_columns did. Add "keyType" => "cleansed" to keep their keys cleansed, such as last_login for the column Last Login: without it they are keyed as they are in the file, so record["last_login"] is nil, without an error. |
header_cleanser: :none |
"fieldsMatch" => "subset", "extraColumns" => "keep" and "fields" => [], which keeps every column, named as it is in the file, without keyType. |
columns, for a file without a header row |
"header" => false, with a field for each column, in order, named as the column was, without keyType. A nil column is a field with "skip" => true, which holds its place. |
format_options with a fixed width layout |
The width of each field, and "keyType" => "symbol" when the keys of the layout are Symbols. |
7.0 did not apply allowed_columns, required_columns or skip_unknown in three cases, so leave them
out of the schema there, rather than describe them, or the schema starts rejecting or dropping columns
that 7.0 kept:
- to JSON records, which keep every key, as they are named,
- to
columnssupplied for a file without a header row, and - with
header_cleanser: :none.
With format: :auto they applied to a CSV or PSV file but not to a JSON file, which one schema cannot
do, so choose what each kind of file needs.
A schema keeps the letters that are not ASCII in a column’s name, where 7.0 removed them, so rename a
field such as prnom, for the column Prénom, to prénom. Otherwise "partial", "subset" and
"superset" skip that column without an error.
Before applying a schema to a job, read a recent file of the job with it, and compare the records with those that the job receives now.
With a schema, the keys of each record are the names of its fields, and the columns of the header row
are matched to them whatever their case, spaces and punctuation, rather than cleansed. So a field
named last_login reads the column Last Login, and a field named Last Login keeps that key.
fieldsMatch defaults to "exact": the columns must be the fields, in order, and a column that is not
a field raises IOStreams::Errors::InvalidHeader. Use "subset" or "partial" to skip the other
columns, as skip_unknown: true did. See
Moving the column options to a schema.
The deprecated options cannot be set with a schema, and a category that sets both is not valid. An
input category’s columns can still be set with a schema, and are not deprecated with one: upload
sets them to the header row read from the file, as it is in the file, which the workers match to the
fields.
Upload modes with a schema
A category with a schema cannot use the :array mode, nor be uploaded with stream_mode: :array.
Use the default :line mode, in which each worker parses its lines, or :hash to also parse every
line when the file is uploaded, so that a file with a problem is found before it is processed. Both
upload the lines of the file, so that #perform receives each value as its type, such as a Date.
Without a schema, a category’s mode does not change how a file is uploaded: its lines are uploaded.
stream_mode: :array still parses each line into an Array, as in v7.0, except that IOStreams 2.2
deprecates reading a JSON file as Arrays. For an upload of a JSON file with stream_mode: :array,
IOStreams reports each(:array) as deprecated at a line of Rocket Job (category/input.rb), not of
your application: use stream_mode: :hash, which uploads the same Hashes.
Columns of a header row that are the same key
Without a schema, the columns of a header row are cleansed into the keys of each record, so a and
A, or First Name and first_name, are the same key, and each record holds the value of only the
last of them. IOStreams 2.2 deprecates reading such a file, and IOStreams 3.0 raises for it, so
Rocket Job reports a deprecation warning at the line that uploads it. Rename the columns of the file,
or describe them with the category’s schema, where two columns that match the same field raise
IOStreams::Errors::InvalidHeader.
Text is read as UTF-8 with a schema
The text of a file uploaded into a category with a schema is read as UTF-8, so letters that are not
ASCII, such as José, are kept, and text that is not valid UTF-8 raises
IOStreams::Errors::InvalidEncoding, and uploads nothing. Without a schema, a tabular upload still
removes every character that is not ASCII, as in v7.0, so moving a job to a schema keeps letters that
it used to lose. An encoding set on the path that is uploaded is used instead.
Find the deprecated options that you use
Rocket Job reports a Ruby deprecation warning for each deprecated category option that it is given,
naming the line of the job class that defines the category, or of the call to upload that supplies
one, such as allowed_columns:, for example:
app/jobs/import_job.rb:5: warning: Rocket Job: allowed_columns:, skip_unknown: are deprecated, describe the columns of the file with schema: instead, see https://rocketjob.reidmorrison.com/upgrading.html#upgrading-to-v71
A Dirmon entry or an UploadFileJob whose properties hold a deprecated option reports one when it
builds its job, without the line of a job class.
An option passed to upload, such as allowed_columns:, is reported twice: by Rocket Job, at the
line that calls upload, and by IOStreams, since Rocket Job passes it on. Change the call to upload
that Rocket Job’s warning names.
IOStreams also reports what Rocket Job passes on from a call to upload or download, such as a
deprecated form of a path, like job.upload("~/in.csv"), or a JSON file uploaded with
stream_mode: :array, see Upload modes with a schema. Such a warning
names a line of Rocket Job, such as lib/rocket_job/category/input.rb, rather than of your
application, so find the call to upload or download that supplied it, and change that.
The warnings are only reported while Ruby’s deprecation warnings are on, which they are in tests run
by Minitest, or with ruby -W:deprecated or RUBYOPT=-W:deprecated, so production stays quiet. A job
that was saved with a deprecated option, and is read back, does not report one. IOStreams reports its
own deprecation warnings, prefixed IOStreams:, for the methods and options that the application
calls on it.
Check the paths and stream options saved in the database
IOStreams 2.2 also deprecates some forms of paths and stream options, such as a local file name that
starts with ~/, see
Deprecated, and what replaces it.
IOStreams reports one only when the path is used, so tests seldom report those that are saved in the
database. Rocket Job passes these to IOStreams:
- the
patternandarchive_directoryof each Dirmon entry, and the paths in itsproperties, - the
source_url,target_url, arguments and streams of eachCopyFileJob, - the
upload_file_nameandoriginal_file_nameof eachUploadFileJob, - the
file_nameof each category of a batch job, and - each field of your own of type
IOStreams::Path.
To have IOStreams report most of them, run this in a console of the application, such as
bin/rails console. It reads each Dirmon entry and job, and builds its paths without opening them:
Warning[:deprecated] = true
RocketJob::DirmonEntry.each do |entry|
puts "Dirmon entry #{entry.name}:"
IOStreams.path(entry.pattern)
IOStreams.path(entry.archive_directory) if entry.archive_directory.present?
end
RocketJob::Job.each do |job|
puts "#{job.class.name} #{job.id}:"
case job
when RocketJob::Jobs::CopyFileJob
job.source_path if job.source_url
job.target_path
when RocketJob::Jobs::UploadFileJob
job.upload_file_name
when RocketJob::Batch
job.input_categories.each(&:file_name)
job.output_categories.each(&:file_name)
end
end
Each warning follows the name of the Dirmon entry or job that holds the path. Check the paths in the
properties of Dirmon entries, the original_file_name of each UploadFileJob, and your own fields
by hand.
Upgrading to v6
- Support for Ruby v3 and Rails 6.
- Major enhancements in Batch job support:
- Direct built-in Tabular support for all input and output categories.
- Multiple output file support, each with its own settings for:
- Compression: GZip, Zip, BZip2 (chunked for much faster loading into Apache Spark).
- Encryption: PGP, Symmetric Encryption.
- File format: CSV, PSV, JSON, Fixed Format, xlsx.
- Significant error handling improvements, especially around throttle failures that used to result in “hanging” jobs.
- Removed use of Symbols to meet the Symbol deprecation in MongoDB and Mongoid.
Deprecated Tabular plugins
The following plugins have been deprecated and are no longer loaded by default.
RocketJob::Batch::Tabular::InputRocketJob::Batch::Tabular::Output
If your code relies on these plugins and you still want to upgrade to Rocket Job v6, add the following require statement to any jobs that still use them:
require "rocket_job/batch/tabular"
It is important to migrate away from these plugins, since they will be removed in a future release.
Scheduled jobs
For any scheduled jobs that include the RocketJob::Plugins::Cron plugin, the default behavior has
changed so that the scheduled job instance is created immediately after the currently scheduled
instance starts.
To maintain the old behavior of creating the job when it fails, aborts, or completes, add the following line to each of the applicable jobs:
self.cron_after_start = false
Additionally, scheduled jobs now prevent a new one from being created when another scheduled
instance of the same job is already queued, or running with the same cron_schedule.
To maintain the old behavior of allowing multiple instances with the same cron schedule, add the following line to each of the applicable jobs:
self.cron_singleton = false
Since scheduled jobs now implement their own singleton logic, remove the singleton plugin from any scheduled jobs.
Batch jobs
Rocket Job v6 replaces the array of symbols for input_categories and output_categories with an
array of RocketJob::Category::Input and RocketJob::Category::Output.
Jobs that added or modified the input or output categories need to be upgraded. For example:
class MyJob < RocketJob::Job
include RocketJob::Batch
self.output_categories = [:main, :errors, :ignored]
end
Needs to be changed to:
class MyJob < RocketJob::Job
include RocketJob::Batch
output_category name: :main
output_category name: :errors
output_category name: :ignored
end
slice_size, encrypt, compress
These fields have been removed from the job itself:
class MyJob < RocketJob::Job
include RocketJob::Batch
self.slice_size = 1_000
self.encrypt = true
self.compress = true
end
They are now specified on the input_category as follows:
slice_sizejust moves underinput_category.encryptbecomes an option toserializer.compressis now the default for all batch jobs, so it is not needed.
If the serializer is set to encrypt then it is automatically compressed.
class MyJob < RocketJob::Job
include RocketJob::Batch
input_category slice_size: 1_000, serializer: :encrypt
end
collect_output, collect_nil_output
The following fields have been moved from the job itself:
class MyJob < RocketJob::Job
include RocketJob::Batch
self.collect_output = true
self.collect_nil_output = true
end
Into the corresponding output_category:
collect_outputno longer has any meaning. Output is collected anytime anoutput_categoryis defined.collect_nil_outputis now the optionnilson theoutput_category. It defaults tofalseso that by default anyniloutput from theperformmethod is not collected.
class MyJob < RocketJob::Job
include RocketJob::Batch
output_category nils: true
end
Category name
For both input_category and output_category, when the name argument is not supplied it
defaults to :main. For example:
class MyJob < RocketJob::Job
include RocketJob::Batch
input_category name: :main, serializer: :encrypt
output_category name: :main
end
Is the same as:
class MyJob < RocketJob::Job
include RocketJob::Batch
input_category serializer: :encrypt
output_category
end
Existing and in-flight jobs
When migrating to Rocket Job v6, it is recommended to load every job and then save it back again as part of the deployment. When the job loads it will automatically convert itself from the old schema to the new v6 schema.
In-flight jobs should not be affected, other than it is important to shut down all running batch servers before running any new instances.
Upgrading to v3
V3 replaces MongoMapper with Mongoid, which supports the latest MongoDB Ruby client driver.
Mongo config file
Replace mongo.yml with mongoid.yml. Start with the sample
mongoid.yml.
Note: the rocketjob and rocketjob_slices clients in the above mongoid.yml file are both
required.
Other changes
Arguments are no longer supported. Use fields for defining all named arguments for a job.
Replace usages of rocket_job do to set default values:
rocket_job do |job|
job.priority = 25
end
With:
self.priority = 25
Replace key with field when adding attributes to a job:
key :inquiry_defaults, Hash
With:
field :inquiry_defaults, type: Hash, default: {}
Replace usage of public_rocket_job_properties with the user_editable option:
field :priority, type: Integer, default: 50, user_editable: true