-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from aclowes/simple-tasks
allow tasks without an associated workflow
- Loading branch information
Showing
21 changed files
with
185 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.2 on 2017-06-29 16:44 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('yawn', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='queue', | ||
name='name', | ||
field=models.TextField(unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name='task', | ||
name='run', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='yawn.Run'), | ||
), | ||
migrations.AlterField( | ||
model_name='template', | ||
name='name', | ||
field=models.TextField(), | ||
), | ||
migrations.AlterField( | ||
model_name='template', | ||
name='workflow', | ||
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.PROTECT, | ||
to='yawn.Workflow'), | ||
), | ||
migrations.AlterField( | ||
model_name='workflowname', | ||
name='name', | ||
field=models.TextField(unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import shlex | ||
|
||
from yawn.task.models import Template, Task | ||
from yawn.workflow.models import Workflow # noqa - needed to load the foreign key! | ||
from yawn.worker.models import Queue | ||
|
||
|
||
def delay(func, *args, timeout=None, max_retries=0, queue=None): | ||
arguments = [shlex.quote(arg) for arg in args] | ||
command = 'yawn exec {0.__module__} {0.__name__} {1}'.format( | ||
func, ' '.join(arguments)).strip() | ||
task_name = '{0.__module__}.{0.__name__}({1})'.format( | ||
func, ', '.join(arguments)) | ||
|
||
if queue: | ||
queue_obj, _ = Queue.objects.get_or_create(name=queue) | ||
else: | ||
queue_obj = Queue.get_default_queue() | ||
|
||
template, _ = Template.objects.get_or_create( | ||
name=task_name, | ||
command=command, | ||
queue=queue_obj, | ||
max_retries=max_retries, | ||
timeout=timeout | ||
) | ||
task = Task.objects.create( | ||
template=template | ||
) | ||
task.enqueue() | ||
return task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from yawn.task.helpers import delay | ||
|
||
|
||
def some_function(*args): | ||
pass | ||
|
||
|
||
class SomeClass: | ||
pass | ||
|
||
|
||
def test_quoted_arg(): | ||
task = delay(SomeClass, 'A small "taste" of chaos') | ||
assert task.template.command == 'yawn exec yawn.task.tests.test_helpers ' \ | ||
'SomeClass \'A small "taste" of chaos\'' | ||
|
||
|
||
def test_many_args(): | ||
task = delay(some_function, 'something', '1') | ||
assert task.template.command == "yawn exec yawn.task.tests.test_helpers " \ | ||
"some_function something 1" | ||
|
||
|
||
def test_deduplication(): | ||
task1 = delay(some_function) | ||
task2 = delay(some_function) | ||
assert task1.template_id == task2.template_id | ||
|
||
|
||
def test_queued(): | ||
task = delay(SomeClass, queue='queue', max_retries=2, timeout=10) | ||
assert task.message_set.count() == 1 | ||
assert task.message_set.first().queue.name == 'queue' | ||
assert task.template.max_retries == 2 | ||
assert task.template.timeout == 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.