Skip to content

Commit

Permalink
WIP - task reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Signorini committed Dec 13, 2018
1 parent 1b7b3a7 commit abb69fb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/services/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.libs.logger import logger
from app.repository.singleton import Singleton
from app.services.maps.spawn_map import SpawnMap
from app.tasks import task_connections, task_webhook, task_counter
from app.tasks import task_connections, task_webhook, task_counter, task_reports


class SpawnJobs(object, metaclass=Singleton):
Expand Down Expand Up @@ -59,9 +59,10 @@ def is_disabled(sjob):

@staticmethod
def caller(task, args):
tasks = {'connections': task_connections, 'webhook': task_webhook}
tasks = {'connections': task_connections, 'webhook': task_webhook, 'reports': task_reports}

if task in tasks:

task_id = tasks[task].delay(**args)
counter_id = task_counter.delay(_id=args.get('_id'))
logger.info('Scheduler: Task executed %s (%s)', task_id, counter_id)
logger.info('Scheduler: Task executed %s (%s)', task_id, counter_id)
1 change: 1 addition & 0 deletions app/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .notify_event import task_notify_event
from .webhook import task_webhook
from .connections import task_connections
from .reports import task_reports
from .counter import task_counter
from .crawling_job import task_crawling
from .depleted_job import task_deplete
2 changes: 2 additions & 0 deletions app/tasks/chain_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
def task_chain_exec(task, args):
import app.tasks.webhook as module_webhook
import app.tasks.connections as module_connections
import app.tasks.reports as module_reports

tasks = {
'connections': module_connections.task_connections,
'reports': module_reports.task_reports,
'webhook': module_webhook.task_webhook
}

Expand Down
24 changes: 24 additions & 0 deletions app/tasks/reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re
import requests
import json

from app import celery

from app.libs.url import FactoryURL
from app.tasks.webhook import task_webhook
from app.tasks.depleted_job import task_deplete


@celery.task(name="reports")
def task_reports(name, _id, endpoint, method="GET", args=[], params={}, chain=[]):
print(name, _id, endpoint, method, args, params, chain)
query = json.dumps({
'_id': _id,
'active': True
})

path = FactoryURL.make(path="reports")
resource = requests.post(path, json={'query': query})


return {_id}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "run.py",
"scripts": {
"beat": "python run.py",
"worker": "celery -A app.celery worker --loglevel=info",
"worker": "celery -A app.celery worker -E -Q scheduler --hostname=scheduler@%h --loglevel=info",
"save": "pip freeze -l > requirements.txt ",
"test": "python -m unittest discover",
"package-flask": "docker build -t scheduler-maestro .",
Expand Down

0 comments on commit abb69fb

Please sign in to comment.