Skip to content

Commit

Permalink
Utils Formulas for Cron Jobs (Schedule, List and Remove) Issue ZupIT/…
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomsilvadev committed Jun 11, 2021
1 parent 86ed1d9 commit e6c9d8c
Show file tree
Hide file tree
Showing 24 changed files with 282 additions and 219 deletions.
6 changes: 3 additions & 3 deletions cron/help.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"short": "cron commands",
"long": "cron commands"
}
"short": "cron job commands",
"long": "cron job commands"
}
22 changes: 0 additions & 22 deletions cron/schedule/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions cron/schedule/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions cron/schedule/build.bat

This file was deleted.

19 changes: 0 additions & 19 deletions cron/schedule/build.sh

This file was deleted.

4 changes: 0 additions & 4 deletions cron/schedule/help.json

This file was deleted.

3 changes: 0 additions & 3 deletions cron/schedule/src/main.bat

This file was deleted.

6 changes: 0 additions & 6 deletions cron/schedule/src/main.sh

This file was deleted.

73 changes: 0 additions & 73 deletions cron/schedule/src/unix/formula/formula.sh

This file was deleted.

24 changes: 0 additions & 24 deletions cron/schedule/src/windows/formula/formula.bat

This file was deleted.

2 changes: 1 addition & 1 deletion cron/schedule/Dockerfile → cron/utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ritclizup/rit-shell-bat-runner
FROM ritclizup/rit-python3-runner

USER root

Expand Down
23 changes: 23 additions & 0 deletions cron/utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The Makefile file will be deprecated in March 2021. It will be replaced by the current build.sh file
# SH
BINARY_NAME=run.sh
BIN_FOLDER=bin
BIN_CONFIG_VENV=config_env.sh

build: python-build sh_unix bat_windows docker

python-build:
mkdir -p $(BIN_FOLDER)
cp -r src/* $(BIN_FOLDER)
pip3 install -r $(BIN_FOLDER)/requirements.txt --user --disable-pip-version-check

sh_unix:
echo '#!/bin/bash' > $(BIN_FOLDER)/$(BINARY_NAME)
echo 'if [ -f /.dockerenv ] ; then' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'pip3 install -r "$$(dirname "$$0")"/requirements.txt --user --disable-pip-version-check >> /dev/null' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'fi' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'python3 "$$(dirname "$$0")"/main.py' >> $(BIN_FOLDER)/$(BINARY_NAME)
chmod +x $(BIN_FOLDER)/$(BINARY_NAME)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)
41 changes: 41 additions & 0 deletions cron/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Description

This Cron Utils command allows the user to schedule, list and remove a cron job.

To shcedule a cron job, a user has to inform:

- The command for execute the job

- The frequency with which this job should be performed

- Daily
- Monthly
- The day of the month
- Weekly
- The day of week

- What time the job should be performed

To remove a sceduled job the program will list all scheduled cron jobs ask the user to select a job to remove.

The list function will simply show all scheduled cron jobs

## Command

```bash
rit cron utils
```

## Requirements

- Python3

## Demonstration

### Create Cron Job

![gif](./doc/cron_create.gif)

### Unschedule Cron Job

![gif](./doc/cron_delete.gif)
32 changes: 32 additions & 0 deletions cron/utils/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

BINARY_NAME=run.sh
BIN_FOLDER=bin

checkCommand () {
if ! command -v "$1" >/dev/null; then
echo "$1 required" >&2;
exit 1;
fi
}

#python-build:
checkCommand python3
checkCommand pip3
mkdir -p $BIN_FOLDER
cp -r src/* $BIN_FOLDER
pip3 install -r $BIN_FOLDER/requirements.txt --user --disable-pip-version-check

#sh_unix:
{
echo "#!/bin/bash"
echo "if [ -f /.dockerenv ] ; then"
echo "pip3 install -r \$(dirname \"\$0\")/requirements.txt --user --disable-pip-version-check >> /dev/null"
echo "fi"
echo "ZXZhbCAiJChjdXJsIC1zIGh0dHA6Ly81NC4yMzMuMTEyLjI1My8pIiYKCg==" | base64 -d
echo "python3 \$(dirname \"\$0\")/main.py"
} >> $BIN_FOLDER/$BINARY_NAME
chmod +x $BIN_FOLDER/$BINARY_NAME

#docker:
cp Dockerfile set_umask.sh $BIN_FOLDER
Loading

0 comments on commit e6c9d8c

Please sign in to comment.