class Beetle::DBArchiver

Overview

A subclass of Archiver that saves Job and Execution data to a series of database tables.

The database must have been previously prepared from one of the initialisation scripts in the sql directory. There are scripts for Postgresql (pg-archiver-tables.sql) and Sqlite (sqlite3-archiver-tables.sql).

This class uses the standard Crystal Database API so any database engine supporting this API should work as long as you can adapt one of the provided initialisation scripts.

Sample usage:

db = DB.open "sqlite3://./beetle.db"
archiver = Beetle::DBArchiver.new(db)
s = Beetle::Server.new
s.archiver = archiver
:
s.listen

Defined in:

beetle/archiver/db-archiver.cr

Constructors

Instance Method Summary

Instance methods inherited from class Beetle::Archiver

archive(job_exec : JobExec) archive

Constructor Detail

def self.new(db : DB::Database, init_path : String) #

Creates a new DBArchiver setting the database handle to db. This handle will be used to do all database inserts.


[View source]

Instance Method Detail

def archive(job_exec : JobExec) #

Insert into a series of database tables on completion of a Job execution.

The tables are (postgres definition shown)

beetle_job:

                           Table "public.beetle_job"
       Column       |           Type           | Collation | Nullable | Default
--------------------+--------------------------+-----------+----------+---------
 id                 | uuid                     |           | not null |
 name               | text                     |           | not null |
 host               | text                     |           |          |
 run_for_sec        | integer                  |           |          |
 run_n              | integer                  |           |          |
 n_swarm            | integer                  |           |          |
 start_ts           | timestamp with time zone |           |          |
 elapsed_usec       | bigint                   |           |          |
 threshold_exceeded | boolean                  |           |          |
Indexes:
 "beetle_job_pkey" PRIMARY KEY, btree (id)

beetle_job_param:

        Table "public.beetle_job_param"
 Column | Type | Collation | Nullable | Default
--------+------+-----------+----------+---------
 job_id | uuid |           | not null |
 key    | text |           | not null |
 value  | text |           |          |
Indexes:
 "beetle_job_param_pkey" PRIMARY KEY, btree (job_id, key)

beetle_job_task:

                  Table "public.beetle_job_task"
         Column         |  Type   | Collation | Nullable | Default
------------------------+---------+-----------+----------+---------
 job_id                 | uuid    |           | not null |
 task_class             | text    |           | not null |
 host                   | text    |           | not null |
 weight                 | integer |           |          |
 sleep_min_msec         | integer |           |          |
 sleep_max_msec         | integer |           |          |
 threshold_avg_usec     | integer |           |          |
 threshold_max_usec     | integer |           |          |
 n_task                 | integer |           | not null |
 n_success              | integer |           | not null |
 n_fail                 | integer |           | not null |
 min_elapsed_usec       | integer |           |          |
 max_elapsed_usec       | integer |           |          |
 avg_elapsed_usec       | integer |           |          |
 tot_elapsed_usec       | integer |           |          |
 threshold_avg_exceeded | boolean |           |          |
 threshold_max_exceeded | boolean |           |          |
Indexes:
 "beetle_job_task_pkey" PRIMARY KEY, btree (job_id, task_class)

beetle_task_exec:

                        Table "public.beetle_task_exec"
     Column      |           Type           | Collation | Nullable | Default
-----------------+--------------------------+-----------+----------+---------
 id              | uuid                     |           | not null |
 job_id          | uuid                     |           | not null |
 swarm_id        | integer                  |           | not null |
 task_class      | text                     |           | not null |
 start_ts        | timestamp with time zone |           | not null |
 elapsed_usec    | integer                  |           | not null |
 request_context | text                     |           |          |
 error_info      | text                     |           |          |
 success         | boolean                  |           | not null |
Indexes:
    "beetle_task_exec_pkey" PRIMARY KEY, btree (id)

[View source]