Skip to content

Commit

Permalink
Merge pull request #1186 from scieloorg/beta
Browse files Browse the repository at this point in the history
Incorporação de códigos estáveis
  • Loading branch information
gustavofonseca committed Aug 14, 2015
2 parents 84d360c + 6ade04e commit 72449a4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 69 deletions.
52 changes: 1 addition & 51 deletions docs/dev/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,7 @@ Description of tasks developed in SciELO Manager and their responsibilities
List all tasks:
---------------

1. **articletrack.tasks.do_expires_checkin(checkin)**

Responsible to expire a single checkin.

* **Periodic task**: No.
* **Args**:

* ``checkin``: a checkin object, normally this checkin comply with conditions to be expired (``checkin.is_expirable == True``).

* **Output**: None.
* **Retry when**: Can't contact Balaio, or RPC call fails.

The task will contact Balaio's RPC API and requests to expire the checkin, if this call succeed, then change the checkin status to ``expired``, by calling : ``checkin.do_expires()``.

2. **articletrack.tasks.process_expirable_checkins()**

Responsible to collect all expirable checkins, and enqueue checkins to be processed by ``articletrack.tasks.do_expires_checkin``.

* **Periodic task**: Yes (registered in Celery Beat to run daily at 00:00 hs).
* **Args**: None.
* **Output**: None.
* **Retry**: No, all unprocessed checkins, will be collected the next run.

The task filters all expirable checkins (all checkins with status ``pending`` and with any expiration date), for each checkin, if comply with: ``checkin.is_expirable == True`` will be processed.
Every matching checkin, will have expiration date previous or equals than current date, then will be enqueued to be processed by the task: **articletrack.do_expires_checkin(...)** that effectively expires the checkins.

3. **scielomanager.send_mail(self, subject, content, to_list, html=True)**
1. **scielomanager.send_mail(self, subject, content, to_list, html=True)**

Responsible to send an email, based in the args.

Expand All @@ -47,30 +21,6 @@ List all tasks:
* **Output**: None
* **Retry when**: occurs an error when calling send method

4. **articletrack.tasks.do_proceed_to_checkout(checkin_id)**

Responsible to pick a single checkin, verify that is scheduled to be checked out, contact Balaio RPC API, and proceed with checkout process.

* **Periodic task**: No.
* **Args**:

* ``checkin_id``: the id of the checkin to be processed.

* **Output**: None.
* **Retry when**: Can't contact Balaio, or RPC call fails.

The task retrieves the checkin by the id, verifies if comply with requirements to be schedulede to be checked out, then contact Balaio RPC API, and requests to proceed to checkout, then if all succeeded, change the checkin status to ``checkout_confirmed`` by calling: ``checkin.do_confirm_checkout()``

5. **articletrack.tasks.process_checkins_scheduled_to_checkout**

Responsible to collect all the checkins scheduled to be checked out (``checkin.status == 'checkout_scheduled'``), and enqueue checkins to be processed by ``articletrack.tasks.do_proceed_to_checkout``.

* **Periodic task**: Yes (registered in Celery Beat to run hourly).
* **Args**: None.
* **Output**: None.
* **Retry**: No, all unprocessed checkins, will be collected the next run.


Default Retrying Policy:
------------------------

Expand Down
33 changes: 33 additions & 0 deletions scielomanager/journalmanager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,36 @@ def create_article_from_string(xml_string):

return new_article.aid


@app.task(ignore_result=True)
def rebuild_article_domain_key(article_pk):
""" Reconstroi a chave de domínio do artigo.
Atenção: Essa task não é utilizada pelo projeto e pode ser removida
a qualquer momento.
https://github.com/scieloorg/scielo-manager/issues/1183
"""
try:
article = models.Article.nocacheobjects.get(pk=article_pk)
except models.Article.DoesNotExist:
logger.info('Cannot find Article with pk: %s.', article_pk)
return None

# a chave é gerada automaticamente ao salvar o objeto e
# o artigo não precisa ser reindexado no Elasticsearch
article.save()


@app.task(ignore_result=True)
def rebuild_articles_domain_key():
""" Dispara a tarefa de reconstrução da chave de domínio para todos artigos.
Atenção: Essa task não é utilizada pelo projeto e pode ser removida
a qualquer momento.
https://github.com/scieloorg/scielo-manager/issues/1183
"""
articles = models.Article.objects.all()

for article in articles:
rebuild_article_domain_key.delay(article.pk)

10 changes: 0 additions & 10 deletions scielomanager/scielomanager/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@
from datetime import timedelta

CELERYBEAT_SCHEDULE = {
'checkin-expire-daily': {
'task': 'articletrack.tasks.process_expirable_checkins',
'schedule': crontab(minute=0, hour=0),
'args': ()
},
'process-checkins-scheduled-to-checkout-hourly': {
'task': 'articletrack.tasks.process_checkins_scheduled_to_checkout',
'schedule': timedelta(hours=1),
'args': ()
},
'process-orphan-articles-daily': {
'task': 'journalmanager.tasks.process_orphan_articles',
'schedule': crontab(minute=0, hour=0),
Expand Down
46 changes: 38 additions & 8 deletions scielomanager/scielomanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,58 @@

FIXTURE_DIRS = (os.path.join(HERE, 'fixtures'),)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
# Reconfiguração total do sistema de logs do projeto.
# http://stackoverflow.com/a/22336174
LOGGING_CONFIG = None
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'disable_existing_loggers': True,
'formatters': {
'simple': {
'format': '%(asctime)s %(name)s[%(process)d] [%(levelname)s] %(message)s',
},
},
'handlers': {
'console': {
'level': 'NOTSET',
'class': 'logging.StreamHandler',
'formatter': 'simple',
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'ERROR',
},
'django.request': {
'handlers': ['mail_admins'],
'handlers': ['console', 'mail_admins'],
'level': 'ERROR',
'propagate': True,
'propagate': False,
},
'thrift': {
'handlers': ['console', 'mail_admins'],
'level': 'INFO',
'propagate': False,
},
'health': {
'handlers': ['console', 'mail_admins'],
'level': 'INFO',
'propagate': False,
},
'packtools': {
'handlers': ['console', 'mail_admins'],
'level': 'INFO',
'propagate': False,
},
}
}
import logging.config
logging.config.dictConfig(LOGGING)


AUTH_PROFILE_MODULE = 'journalmanager.UserProfile'

Expand Down

0 comments on commit 72449a4

Please sign in to comment.