Skip to content

Commit

Permalink
Merge pull request #109 from JonatanMartens/development
Browse files Browse the repository at this point in the history
v2.2.3
  • Loading branch information
JonatanMartens authored Jan 12, 2021
2 parents f83e992 + 6480774 commit 553e0e2
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8]

container: python:${{ matrix.python-version }}
steps:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/test-zeebe-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
zeebe-version: [ "0.23.6", "0.24.3" ]
python-version: [ 3.5, 3.6, 3.7, 3.8 ]
zeebe-version: [ "0.23.7", "0.24.6", "0.25.3" ]

container: python:${{ matrix.python-version }}
container: python:3.6

services:
zeebe:
image: camunda/zeebe:${{ matrix.zeebe-version }}
ports:
- 26500/tcp


steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
pip install pipenv
pipenv install --dev
- name: Sleep for 30 seconds
uses: jakejarvis/wait-action@master
with:
time: '30s'

- name: Run integration tests
run: |
pipenv run pytest tests/integration
12 changes: 5 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ verify_ssl = true
autopep8 = "~=1.5.4"
pylint = "~=2.6.0"
coverage = "~=5.3"
pytest = "~=6.1.1"
pytest = "~=6.2.1"
pytest-grpc = "~=0.8.0"
mypy = "~=0.790"
coveralls = "~=2.1.2"
importlib-metadata = "~=2.0.0"
coveralls = "~=2.2.0"
importlib-metadata = "~=3.3.0"
pyzeebe = {editable = true, path = "."}
sphinx = "~=3.2.1"
sphinx = "~=3.4.2"
sphinx-rtd-theme = "*"

[packages]
grpcio = "~=1.32.0"
protobuf = "~=3.13.0"
oauthlib = "~=3.1.0"
requests-oauthlib = "~=1.3.0"
zeebe-grpc = "~=0.24.3.3"
zeebe-grpc = "~=0.25.1.0"
525 changes: 256 additions & 269 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Zeebe version support:

| Pyzeebe version | Tested Zeebe versions |
|:---------------:|----------------|
| 2.x.x | 0.23, 0.24 |
| 2.x.x | 0.23, 0.24, 0.25 |
| 1.x.x | 0.23, 0.24 |

## Getting Started
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
author = 'Jonatan Martens'

# The full version, including alpha/beta/rc tags
release = '2.1.0'
release = '2.2.3'

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -59,6 +59,6 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

version = "2.2.2"
version = "2.2.3"

master_doc = 'index'
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Creating a client
Dependencies
============

* python 3.5+
* python 3.6+
* zeebe-grpc
* grpcio
* protobuf
* oauthlib
Expand Down
2 changes: 1 addition & 1 deletion pyzeebe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.2"
__version__ = "2.2.3"

from pyzeebe import exceptions
from pyzeebe.client.client import ZeebeClient
Expand Down
1 change: 1 addition & 0 deletions pyzeebe/grpc_internals/zeebe_adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

logger = logging.getLogger(__name__)


class ZeebeAdapterBase(object):
def __init__(self, hostname: str = None, port: int = None, credentials: BaseCredentials = None,
channel: grpc.Channel = None, secure_connection: bool = False):
Expand Down
2 changes: 1 addition & 1 deletion pyzeebe/grpc_internals/zeebe_job_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from pyzeebe.grpc_internals.zeebe_adapter_base import ZeebeAdapterBase
from pyzeebe.job.job import Job


logger = logging.getLogger(__name__)


class ZeebeJobAdapter(ZeebeAdapterBase):
def activate_jobs(self, task_type: str, worker: str, timeout: int, max_jobs_to_activate: int,
variables_to_fetch: List[str], request_timeout: int) -> Generator[Job, None, None]:
Expand Down
24 changes: 19 additions & 5 deletions pyzeebe/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from pyzeebe.worker.task_handler import ZeebeTaskHandler, default_exception_handler
from pyzeebe.worker.task_router import ZeebeTaskRouter


logger = logging.getLogger(__name__)


class ZeebeWorker(ZeebeTaskHandler):
"""A zeebe worker that can connect to a zeebe instance and perform tasks."""

Expand All @@ -37,6 +37,7 @@ def __init__(self, name: str = None, request_timeout: int = 0, hostname: str = N
self.name = name or socket.gethostname()
self.request_timeout = request_timeout
self.stop_event = Event()
self._task_threads: List[Thread] = []

def work(self) -> None:
"""
Expand All @@ -50,14 +51,25 @@ def work(self) -> None:
"""
for task in self.tasks:
task_thread = Thread(target=self._handle_task, args=(task,))
task_thread = Thread(target=self._handle_task,
args=(task,),
name=f"{self.__class__.__name__}-Task-{task.type}")
task_thread.start()
self._task_threads.append(task_thread)

def stop(self) -> None:
def stop(self, wait: bool = False) -> None:
"""
Stop the worker. This will wait for all tasks to complete before stopping
Stop the worker. This will emit a signal asking tasks to complete the current task and stop polling for new.
Args:
wait (bool): Wait for all tasks to complete
"""
self.stop_event.set()
if wait:
logger.debug("Waiting for threads to join")
while self._task_threads:
thread = self._task_threads.pop(0)
thread.join()

def _handle_task(self, task: Task) -> None:
logger.debug(f"Handling task {task}")
Expand All @@ -70,7 +82,9 @@ def _handle_task(self, task: Task) -> None:

def _handle_jobs(self, task: Task) -> None:
for job in self._get_jobs(task):
thread = Thread(target=task.handler, args=(job,))
thread = Thread(target=task.handler,
args=(job,),
name=f"{self.__class__.__name__}-Job-{job.type}")
logger.debug(f"Running job: {job}")
thread.start()

Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

setuptools.setup(
name="pyzeebe",
version="2.2.2",
version="2.2.3",
author="Jonatan Martens",
author_email="[email protected]",
description="Zeebe client api",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/JonatanMartens/pyzeebe",
packages=setuptools.find_packages(exclude=("tests",)),
install_requires=["grpcio==1.32.0", "protobuf==3.13.0", "oauthlib==3.1.0", "requests-oauthlib==1.3.0",
"zeebe-grpc==0.24.3.3"],
install_requires=["oauthlib==3.1.0", "requests-oauthlib==1.3.0", "zeebe-grpc==0.25.1.0"],
exclude=["*test.py", "tests", "*.bpmn"],
keywords="zeebe workflow workflow-engine",
license="MIT",
Expand All @@ -23,5 +22,5 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.5",
python_requires=">=3.6",
)
7 changes: 3 additions & 4 deletions tests/integration/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def task_handler(should_throw: bool, input: str) -> Dict:
def setup():
global zeebe_client, task_handler

t = Thread(target=zeebe_worker.work)
t.start()
zeebe_worker.work()

zeebe_client = ZeebeClient()
try:
Expand All @@ -39,8 +38,8 @@ def setup():
zeebe_client.deploy_workflow("test.bpmn")

yield zeebe_client
zeebe_worker.stop()
t.join()
zeebe_worker.stop(wait=True)
assert not zeebe_worker._task_threads


def test_run_workflow():
Expand Down

0 comments on commit 553e0e2

Please sign in to comment.