Skip to content

Rake tasks

Luka Murn edited this page Jul 1, 2019 · 6 revisions

Delayed jobs

SciNote uses delayed jobs library to do background processing, mostly for the following tasks:

  • Sending emails,
  • Extracting text from uploaded files (full-text search),
  • Generating introduction tutorials,
  • Copying/cloning large database objects,
  • etc.

Best option to run delayed jobs is inside a worker process. To start a background worker process that will execute delayed jobs, run the following command:

rails jobs:work

To clear all currently queued jobs, you can use the following command:

rails jobs:clear

Warning! This is not advised to do on production environments.

Adding users

To simplify adding of new users to the system, couple of special rails tasks have been created.

The first, rails db:add_user simply queries all the information for a specific user via STDIN, and then proceeds to create the user.

The second task, rails db:load_users[file_path,create_orgs] takes 2 parameters as an input:

  • Path to .yml file containing list of users & teams to be added. The YAML file needs to be structured properly - field names must match those in the database, users need to have a name user_<id>, and teams name team_<id>. For an example load users file, see db/load_users_template.yml file.
  • A boolean ('true' or 'false') whether to create individual teams for each user or not.

Data

Team export & import

All data belonging to a single team (including users) can be exported into a portable format (.json master file + folder with all files). To generate an export of individual team, execute the following task: rails data:team_export[team_id]. This will generate a .json master file, and the folder with all team files, in the /tmp directory.

SciNote allows to import all data from this portable format for an individual team into the database. To import the team data, execute the following task: rails data:team_import[path_to_folder].

WARNING! All team users are also ported alongside the team export, but the import script currently doesn't handle user collisions & duplicates.

Team deletion

All data belonging to an individual team can be deleted from within SciNote. This can be done by executing: rails data:team_delete[team_id]

WARNING! This is a non-revertible action!

Cleaning temporary & obsolete data

There are various temporary files that are generated in scope of normal SciNote operations (e.g. when importing samples, when generating various exports, etc.). These files can safely be removed after a period of time.

  • Execute rails data:clean_temp_files to remove all temporary files generated from imports;
  • execute rails exportable_items:cleanup, to remove all exportable items that are past their availability;
  • execute rails tiny_mce_asset:remove_obsolete_images to remove all TinyMCE images which were uploaded into SciNote, but their result/step/... was not saved at the end.
  • execute rails doorkeeper:db:cleanup to remove tokens that are expired according to the configured TTL in Doorkeeper.configuration.access_token_expires_in. By default Doorkeeper is retaining expired and revoked access tokens and grants.

In a similar fashion, users that were either invited, or registered (while having "confirm registrations" flag on), but never confirmed their registration, can safely be deleted after a period of time. Execute rails data:clean_unconfirmed_users to remove all such users.

Calling rails data:clean will execute both data:clean_temp_files and data:clean_unconfirmed_users tasks.

Miscellaneous

Notifications

To generate a new system notification that will be sent to all SciNote users, execute rails notifications:new_system[title, message]. Title & message can contain HTML tags.

Web statistics

To check current login statistics of registered users, use rails web_stats:login task. To check the last login of any user to the system, use rails web_stats:last_login task.

Limit the domain for registrations

By using PostgreSQL constraints, it is possible to enforce that all SciNote users' emails (existing and new users) belong to the specific domain (e.g. yourcompany.com). To setup the constraint, run the following task: rails sign_up_constraint:email_domain[domain]. To drop the constraint, run the task: rails sign_up_constraint:remove_domain.

Release names

To generate a new, quirky release name (from a predefined list of scientists and adjectives), execute rails versions:generate_release_name.