Skip to content

Commit

Permalink
Merge pull request #13 from mikelandzelo173/SIANXKE-390-django-python…
Browse files Browse the repository at this point in the history
…-support

SIANXKE-390: Updated Python and Django support. Changes to pre-commit packages.
  • Loading branch information
nezhar authored Oct 15, 2024
2 parents acecd28 + 4551ac9 commit bb51d2d
Show file tree
Hide file tree
Showing 27 changed files with 228 additions and 85 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**How to reproduce**
Describe how to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEATURE]"
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
15 changes: 15 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Description
Describe your changes or fixes (please link to an issue if applicable)

## Types of changes
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactoring (improvements in base code)
- [ ] Add test (adds test coverage to functionality)

## Checklist
- [ ] Automated tests
- [ ] Extends CHANGELOG.md
- [ ] Requires migrations?
- [ ] Requires dependency update?
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
architecture: 'x64'

- name: Install dependencies
Expand All @@ -38,4 +38,4 @@ jobs:
TWINE_REPOSITORY: ${{ secrets.PYPI_REPOSITORY }}
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_NON_INTERACTIVE: yes
TWINE_NON_INTERACTIVE: yes
16 changes: 11 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ jobs:
fail-fast: false
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
django-version:
- '3.2'
- '4.1'
- '4.2'
- '5.0'
- '5.1'
exclude:
- python-version: '3.9'
django-version: '5.0'
- python-version: '3.9'
django-version: '5.1'

steps:
- uses: actions/checkout@v2
Expand All @@ -31,7 +37,7 @@ jobs:
pip install -r requirements.txt
pip install django~=${{ matrix.django-version }}.0
- name: Run lint and code review with isort and black
- name: Run lint and code review
run: |
pre-commit run --all-files
- name: Run tests with coverage
Expand All @@ -47,4 +53,4 @@ jobs:
manage.py test
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
__pycache__
db.sqlite3
build/*
tests/static/*
tests/static/*
31 changes: 23 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: isort
args: [ "--profile", "black", "--filter-files" ]
- id: check-merge-conflict
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: trailing-whitespace
args: ["--markdown-linebreak-ext=md"]

- repo: https://github.com/psf/black
rev: 23.3.0 # Replace by any tag/version: https://github.com/psf/black/tags
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6.2+
- id: pyupgrade
args: ["--py39-plus"]

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
35 changes: 29 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.3.0]

### Added

- Support for seconds in cron-like tasks
- Support for Django 5.0 and 5.1.
- Support for Python 3.12 and 3.13.

### Changed

- pre-commit configuration

### Removed

- Human readable cron name due to incompatibility of [cron-descriptor](https://github.com/Salamek/cron-descriptor) and [croniter](https://github.com/kiorky/croniter) for seconds
- `cron-descriptor` from requirements
- Support for Django 3.2 and 4.1.
- Support for Python 3.8.

## [1.2.1]

### Added

- Log exceptions in handle_tick in process_future_tasks

## [1.2.0]

### Added

- Allow seconds in cron string settings

## [1.1.2]

### Fixed

- Fixes compatibility between django 3.2 and 4.2 for next planned execution in admin
- Fixes compatibility between Django 3.2 and 4.2 for next planned execution in admin

## [1.1.1]

Expand All @@ -30,14 +48,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.1.0]

### Added

- Support of periodic, cron-like tasks.

## [1.0.0] - 2023-05-05

### Added

- Initial setup.

[Unreleased]: https://github.com/anexia/django-future-tasks/compare/1.1.2...HEAD
[Unreleased]: https://github.com/anexia/django-future-tasks/compare/1.3.0...HEAD
[1.3.0]: https://github.com/anexia/django-future-tasks/releases/tag/1.3.0
[1.2.1]: https://github.com/anexia/django-future-tasks/releases/tag/1.2.1
[1.2.0]: https://github.com/anexia/django-future-tasks/releases/tag/1.2.0
[1.1.2]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.2
[1.1.1]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.1
[1.1.0]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Anexia
Copyright (c) 2024 Anexia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ python manage.py populate_periodic_future_tasks

## Django Compatibility Matrix

If your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.

| This Project | Python Version | Django Version |
|--------------|----------------------|----------------|
| 1.1.* | 3.8, 3.9, 3.10, 3.11 | 3.2, 4.1, 4.2 |
| 1.0.* | 3.8, 3.9, 3.10, 3.11 | 3.2, 4.0, 4.1 |
If your project uses an older version of Django or Django Rest Framework, you can choose an older version of this project.

| This Project | Python Version | Django Version |
|--------------|-----------------------------|----------------|
| 1.3.* | 3.9, 3.10, 3.11, 3.12, 3.13 | 4.2, 5.0, 5.1 |
| 1.2.* | 3.8, 3.9, 3.10, 3.11 | 3.2, 4.1, 4.2 |
| 1.1.* | 3.8, 3.9, 3.10, 3.11 | 3.2, 4.1, 4.2 |
| 1.0.* | 3.8, 3.9, 3.10, 3.11 | 3.2, 4.0, 4.1 |
4 changes: 2 additions & 2 deletions django_future_tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class FutureTaskAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(FutureTaskAdminForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields["type"].widget = forms.Select(choices=settings.FUTURE_TASK_TYPES)

class Meta:
Expand All @@ -25,7 +25,7 @@ class FutureTaskAdmin(admin.ModelAdmin):

class PeriodicFutureTaskAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PeriodicFutureTaskAdminForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields["type"].widget = forms.Select(choices=settings.FUTURE_TASK_TYPES)

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion django_future_tasks/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _validate_CRON_string(value):
p = re.compile(pattern)
for i, c in enumerate(columns):
if not p.match(c):
raise ValidationError("Incorrect value {} in column {}".format(c, i + 1))
raise ValidationError(f"Incorrect value {c} in column {i + 1}")


class FutureTaskCronField(CronField):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def handle_tick(self):
now = timezone.now()
periodic_task_list = self.periodic_tasks_for_processing()
logger.debug(
"Got {} periodic tasks for processing".format(len(periodic_task_list))
f"Got {len(periodic_task_list)} periodic tasks for processing",
)

for p_task in periodic_task_list:
Expand Down Expand Up @@ -89,15 +89,15 @@ def handle(self, *args, **options):

except Exception as exc:
logger.exception(
"%s exception occurred ... " % (exc.__class__.__name__,)
f"{exc.__class__.__name__} exception occurred...",
)

# As the database connection might have failed, we discard it here, so django will
# create a new one on the next database access.
db.close_old_connections()

def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# The command will run as long as the `_running` attribute is
# set to `True`. To safely quit the command, just set this attribute to `False` and the
Expand Down
17 changes: 10 additions & 7 deletions django_future_tasks/management/commands/process_future_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def _handle_options(self, options):
@staticmethod
def tasks_for_processing():
return FutureTask.objects.filter(
eta__lte=timezone.now(), status=FutureTask.FUTURE_TASK_STATUS_OPEN
eta__lte=timezone.now(),
status=FutureTask.FUTURE_TASK_STATUS_OPEN,
)

@staticmethod
Expand All @@ -55,7 +56,7 @@ def _convert_exception_args(args):

def handle_tick(self):
task_list = self.tasks_for_processing()
logger.debug("Got {} tasks for processing".format(len(task_list)))
logger.debug(f"Got {len(task_list)} tasks for processing")

for task in task_list:
task.status = FutureTask.FUTURE_TASK_STATUS_IN_PROGRESS
Expand All @@ -69,12 +70,14 @@ def handle_tick(self):
except Exception as exc:
task.status = FutureTask.FUTURE_TASK_STATUS_ERROR
task.result = {
"exception": "An exception of type {0} occurred.".format(
type(exc).__name__
"exception": "An exception of type {} occurred.".format(
type(exc).__name__,
),
"args": self._convert_exception_args(exc.args),
"traceback": traceback.format_exception(
*sys.exc_info(), limit=None, chain=None
*sys.exc_info(),
limit=None,
chain=None,
),
}
logger.exception(exc)
Expand All @@ -97,15 +100,15 @@ def handle(self, *args, **options):

except Exception as exc:
logger.exception(
"%s exception occurred ... " % (exc.__class__.__name__,)
f"{exc.__class__.__name__} exception occurred...",
)

# As the database connection might have failed, we discard it here, so django will
# create a new one on the next database access.
db.close_old_connections()

def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# The command will run as long as the `_running` attribute is
# set to `True`. To safely quit the command, just set this attribute to `False` and the
Expand Down
8 changes: 6 additions & 2 deletions django_future_tasks/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class Migration(migrations.Migration):
(
"task_id",
models.CharField(
max_length=255, unique=True, verbose_name="task ID"
max_length=255,
unique=True,
verbose_name="task ID",
),
),
(
Expand All @@ -37,7 +39,9 @@ class Migration(migrations.Migration):
(
"data",
models.JSONField(
blank=True, null=True, verbose_name="Various execution data"
blank=True,
null=True,
verbose_name="Various execution data",
),
),
("type", models.CharField(max_length=255, verbose_name="Task type")),
Expand Down
Loading

0 comments on commit bb51d2d

Please sign in to comment.