Skip to content

cedt-mock-exam/cafegrader-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cafe Grader Manager CLI

Warning

This tool can be used with folkiesss/cafe-grader-docker, but you will need to modify how directories are called by importing the tool into the container. This is because the program still relies on certain OS file operations.

cafegrader-manager was created to help configure the Cafe Grader system together with a Cronjob-style scheduler (crontab), enabling automatic scheduled opening/closing of the system (Admin/Single Mode), deletion of Judge Log files, and enabling/disabling of Contest Mode at specified times.

Features

  • Enable/disable Admin/Single Mode
    • Used to lock the website so that only Administrators can log in.
  • Delete data in the Judge folder (~/cafe_grader/judge/isolate_submission) safely, even over short intervals, compared to the old system. This is well suited for servers with limited hard disk space.
    • With the old system, configuring deletion to run at short intervals (under 30 minutes) could cause problems where the Worker is unable to check program results, resulting in a [!] or [x] verdict.
    • This program can be scheduled to delete files at a per-minute interval and can safely be used during an ongoing exam, because before the system deletes the file/folder for a given Submission ID, it always checks whether that submission is still being processed by a Worker.
    • If a given Submission ID is still being processed by a Worker, it will be skipped and re-checked later.
  • Enable/disable Contest Mode
    • The CLI program currently does not support creating, editing, or deleting Contests themselves. It can only enable Contest Mode globally from the system's settings menu.

Requirements

Database:

  • MySQL or MariaDB

Judge Machine/Instances:

  • crontab
  • cat
  • git
  • curl
  • Text Editor (nano/vim) -- optional
  • GoLang (if you want to compile the binary yourself)

Installation

There are two main installation methods: running the automated script setup-cronjob.sh, or Manual Setup. Steps for each are as follows.

Automated Script

  1. Download the executable from the Releases section of this repository and move it to the directory where you want to store it.
  2. Navigate to the directory where you stored the executable, then run the following command:
curl https://raw.githubusercontent.com/cedt-mock-exam/cafegrader-manager/refs/heads/main/setup-cronjob.sh | bash
  1. Enter the Database credentials (Username, Password, Host, Port, Database Name) and the Judge Directory when prompted by the system.
  2. Once entered successfully, the system will automatically set up a script to clean Judge Logs every 3 hours (you can change this later yourself using the crontab -e command; look for the line referencing cafegrader-manager clean_judge).

Note: If the system reports back no crontab for XXXX, you can ignore this message, as it simply indicates that no cronjob has previously been created on the system.

Manual Setup

  1. Install GoLang in order to compile the binary.
    • You can use a version manager tool (such as asdf) as long as you can run the go version command.
  2. Clone the repository from GitHub using the main branch.
  3. Run the command go build -o cafegrader-manager main.go.
  4. Use the crontab program to configure the schedule for running the program at the desired times.
    • This is typically done using the crontab -e command.
  5. Add a cronjob entry in the following format:
# This is an example for run every hours.
0 * * * * /path/to/cafegrader-manager -u <DB_USER> -p <DB_PASS> -H <DB_HOST> -P <DB_PORT> -d <DB_NAME> -r <CAFE_JUDGE_PATH> [COMMANDS] [ARGS]

# Example for clean judge (Every 3 hours)
0 */3 * * * /home/cafe/cafegrader-manager -u root -p cafe_password -H 127.0.0.1 -P 3306 -d grader -r /var/www/cafe_grader/judge clean_judge

# Example for enable admin mode (Every 02:00AM)
0 2 * * * /home/cafe/cafegrader-manager -u root -p cafe_password -H 127.0.0.1 -P 3306 -d grader admin_mode --admin=true
  1. Once the cronjob has been configured successfully, exit the editor. Crontab will then save the configuration and begin running it at the specified times immediately.

Usage

This program is a CLI (Command Line Interface) tool. You can invoke it using commands in the following format:

# In case use default arguments
cafegrader-manager [FLAGS] [COMMANDS] [ARGS]
cafegrader-manager -p <DB_PASS> admin_mode --admin=<true | false>
cafegrader-manager -p <DB_PASS> clean_judge

# In case use another arguments
cafegrader-manager -u <DB_USER> -p <DB_PASS> -H <DB_HOST> -P <DB_PORT> -d <DB_NAME> admin_mode --admin=<true | false>
cafegrader-manager -u <DB_USER> -p <DB_PASS> -H <DB_HOST> -P <DB_PORT> -d <DB_NAME> -r <CAFE_JUDGE_PATH> clean_judge

For more detailed usage instructions, run cafegrader-manager --help.

About

Cafe Grader Manager CLI - It's tools that used with website and cronjob for auto schedule somes task easily.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors