Skip to content

Commit

Permalink
Setup github actions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
A authored Jul 15, 2024
1 parent 57001eb commit b09327c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 17 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test

on:
push:
branches:
- '*'
- '!master'

env:
PYTHON_VERSION: 3.12.4

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

name: Python ${{ matrix.python-version }} test

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: install poetry
run: pip install poetry

- name: install deps
run: poetry install

- name: test
run: poetry run pytest --cache-clear --cov=zapusk | tee pytest-coverage.txt

- name: Pytest coverage comment
if: matrix.python-version == '3.12'
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./pytest-coverage.txt
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Zapusk is a job runner for desktop environments. It helps you manage background tasks with features like pre-configured job execution, background shell commands, scheduling with cron-like syntax, log tailing, and notifications. It also provides detailed JSON output for easy data manipulation and analysis.


## Key Features

- **Preconfigured Jobs:** Run jobs defined in your configuration files.
Expand Down
42 changes: 29 additions & 13 deletions zapusk/client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
from zapusk.models.job import JOB_STATE_ENUM


doc = """zapusk-client
doc = """zapusk
Usage:
zapusk-client -h | --help
zapusk-client --version
zapusk-client run <job_config_id> [--colors|--no-colors] [--tail]
zapusk-client exec <command> [--name=<name>] [--group=<group>] [--tail] [--schedule=<cron_expression>] [--colors|--no-colors]
zapusk-client cancel <job_id> [--scheduled] [--colors|--no-colors]
zapusk-client tail <job_id>
zapusk-client list [--filter=<state>|--scheduled] [--colors|--no-colors]
zapusk-client config_jobs [--colors|--no-colors]
zapusk-client config_groups [--colors|--no-colors]
zapusk-client waybar
zapusk -h | --help
zapusk --version
zapusk run <job_config_id> [--colors|--no-colors] [--tail]
zapusk exec <command> [--name=<name>] [--group=<group>] [--tail] [--schedule=<cron_expression>] [--colors|--no-colors]
zapusk cancel <job_id> [--scheduled] [--colors|--no-colors]
zapusk tail <job_id>
zapusk list [--filter=<state>|--scheduled] [--colors|--no-colors]
zapusk config_jobs [--colors|--no-colors]
zapusk config_groups [--colors|--no-colors]
zapusk waybar
Options:
Expand All @@ -32,8 +32,24 @@
-t --tail Tail logfile immediately
Examples:
zapusk run upload_to_s3
zapusk status
# Execute npm i in background
zapusk exec "npm i"
# Execute pytest and tail its log
zapusk exec "pytest -v" -t
# Schedule command to run every minute
zapusk exec "pung -c4 google.com" --schedule "*/1 * * * *"
# Run some job defined in ~/.config/zapusk/config.yaml
zapusk run youtube_dl
# Cancel some job with id
zapusk cancel 42
# See logs with id of a job
zapusk tail 42
"""

version = importlib.metadata.version("zapusk")
Expand Down
4 changes: 2 additions & 2 deletions zapusk/client/command_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
class CommandManager:
def __init__(
self,
config_service=ConfigService(),
config_service=None,
output=Output(),
colors=None,
api_client: Optional[ApiClient] = None,
) -> None:
self.output = output
self.config_service = config_service
self.config_service = config_service if config_service else ConfigService()
config = self.config_service.get_config()

self.api_client = (
Expand Down
15 changes: 15 additions & 0 deletions zapusk/client/command_testcase.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
from unittest import TestCase
from unittest.mock import MagicMock
from zapusk.client.api_client import ApiClient
from testfixtures import TempDirectory

from zapusk.services.config.service import ConfigService

from .output import Output
from .command_manager import CommandManager


CONFIG_DATA = ""


class CommandTestCase(TestCase):
def setUp(self) -> None:
self.temp_dir = TempDirectory()
self.config_file = self.temp_dir / "config.yml"
self.config_file.write_text(CONFIG_DATA)
self.config_service = ConfigService(
config_path=f"{self.temp_dir.path}/config.yml"
)

self.printer = MagicMock()
self.output = Output(
printer=self.printer,
Expand All @@ -18,9 +31,11 @@ def setUp(self) -> None:
output=self.output,
api_client=self.api_client,
colors=False,
config_service=self.config_service,
)
return super().setUp()

def tearDown(self) -> None:
self.temp_dir.cleanup()
self.printer.reset_mock()
return super().tearDown()
3 changes: 1 addition & 2 deletions zapusk/services/scheduler_service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


logger = logging.getLogger(__name__)
config_service = ConfigService()


class SchedulerService:
Expand All @@ -22,7 +21,7 @@ def __init__(
interval: float = 1,
) -> None:
self.__interval = interval
self.__config_service = config_service
self.__config_service = config_service if config_service else ConfigService()
self.__executor_manager_service = executor_manager_service
self.__scheduled_jobs = [j for j in config_service.list_jobs() if j.schedule]
logger.info(f"Scheduled jobs detected {[i.id for i in self.__scheduled_jobs]}")
Expand Down

0 comments on commit b09327c

Please sign in to comment.