8000 [8.0] job runner by sbidoul · Pull Request #52 · OCA/connector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[8.0] job runner #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
May 15, 2015
Merged

[8.0] job runner #52

merged 48 commits into from
May 15, 2015

Conversation

sbidoul
Copy link
Member
@sbidoul sbidoul commented Mar 31, 2015

This is an alternative to connector workers that

For more information on how to use it, see the docstring in runner.py.
For more information on job channels, see the docstring of the Channel class in channels.py.

It is safe to try in real deployments because it is fully compatible and it is easy to switch between the new runner and workers.

TODO:

  • can we run the doctests from travis/runbot?
  • there is a couple of todo left in the code, but nothing preventing real life usage according to me


def set_job_enqueued(self, uuid):
with closing(self.conn.cursor()) as cr:
cr.execute("UPDATE queue_job SET state=%s, date_enqueued=NOW() "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the date_enqueued must be truncated to 'seconds'

date_enqueued=date_trunc('seconds', now()::timestamp)

otherwise Odoo will not be able to read it and will raise ValueError

  File "/home/lmi/projects/openerp/openerp-deldrive-buildout/addons-connector/connector/queue/model.py", line 113, in _change_job_state
    job = storage.load(job.uuid)
  File "/home/lmi/projects/openerp/openerp-deldrive-buildout/addons-connector/connector/queue/job.py", line 265, in load
    stored.date_enqueued, DEFAULT_SERVER_DATETIME_FORMAT)
  File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: .024856

@lmignon lmignon mentioned this pull request Apr 3, 2015
@sbidoul sbidoul force-pushed the 8.0-jobrunner-sbi branch from 81e55ad to 4f493b6 Compare April 3, 2015 21:31
@coveralls
Copy link

Coverage Status

Coverage decreased (-14.76%) to 65.31% when pulling 4f493b6 on acsone:8.0-jobrunner-sbi into 6686fd3 on OCA:8.0.

_logger = logging.getLogger(__name__)


class PriorityQueue:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the classes to new-style classes?

@guewen
Copy link
Member
guewen commented Apr 7, 2015

As said before, this is a brilliant work. I added some suggestions or interrogations.
I want to propose a new branch with the channel models / jobs on top of your branch but I fear not to have the time before the 20th of april (holidays from 10th to 19th).
We are testing the 7.0 branch since our customer having the largest number of jobs is on 7.0.

@guewen
Copy link
Member
guewen commented Apr 7, 2015

can we run the doctests from travis/runbot?

Here is a PR: acsone#1

Tests will be executed when --test-enable is used.

@guewen
Copy link
Member
guewen commented Apr 7, 2015

BTW could you rebase your branch?

@guewen
Copy link
Member
guewen commented Apr 7, 2015

Started the implementation of the channels configuration: acsone#2

guewen added a commit to guewen/odoo-connector-magento-buildout that referenced this pull request Apr 9, 2015
@coveralls
Copy link

Coverage Status

Coverage decreased (-8.35%) to 71.72% when pulling a900aec on acsone:8.0-jobrunner-sbi into 6686fd3 on OCA:8.0.

@sbidoul sbidoul force-pushed the 8.0-jobrunner-sbi branch from a900aec to d1f25e9 Compare April 12, 2015 12:54
@sbidoul
Copy link
Member Author
sbidoul commented Apr 12, 2015

I rebased. Thanks for the review @guewen.

@coveralls
Copy link

Coverage Status

Coverage decreased (-8.46%) to 71.61% when pulling 8f150ff on acsone:8.0-jobrunner-sbi into 6686fd3 on OCA:8.0.

channel_name, uuid)
channel = self._root_channel
job = ChannelJob(db_name, channel, uuid,
seq, date_created, priority, eta)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful. In Odoo python date, datetime and time are returned as string by psycopg2. (see https://github.com/odoo/odoo/blob/8.0/openerp/sql_db.py#L61 and http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.new_type). If you assign a string as eta to your ChannelJob you'll get a Comparison error between str and datetime when popping you job at line #L418

    while not self.capacity or len(self._running) < self.capacity:
            job = self._queue.pop(now=datetime.now())

due to #L275

    def pop(self, now):
        if len(self._eta_queue) and self._eta_queue[0].eta <= now:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmignon thanks. I fixed that.

@lmignon
Copy link
Contributor
lmignon commented Apr 21, 2015

👍 it's really a great improvement!

@coveralls
Copy link

Coverage Status

Coverage decreased (-7.38%) to 72.69% when pulling 458a409 on acsone:8.0-jobrunner-sbi into 6686fd3 on OCA:8.0.

@guewen
Copy link
Member
guewen commented Apr 27, 2015

@sbidoul @lmignon We tested the runner (the 7.0 backport) on a production server with ~15000 jobs per day. We encountered "too many connections" issues with postgresql. I think that's only a matter of misconfiguration on our side. Did you issued similar issues ? Do you know how many connections may the runners use to the fullest?

@lmignon
Copy link
Contributor
lmignon commented Apr 27, 2015

@guewen We also encountered the same issue with (+100k jobs/d). If I remember well, you have to change the db_maxconn parameter in your configuration (by default 64).

sbidoul added 14 commits May 14, 2015 22:19
This NOTIFY is not necessary and makes the purge of the job queue very slow.
Thanks to @acsonelmi for the suggestion.
Odoo indeed adapts the psycopg2 type mappings to use strings for datetime.
…able

The presence of ODOO_CONNECTOR_CHANNELS is enough to make the runner
start in place of the workers.
Since the runner is now a thread in the Odoo main process,
such a situation should occur only with a pathologically wrong
configuration, so no need to worry about that... unless proven
otherwise ;)
So the channel module does not make assumptions on the type
of the eta field, so we use the odoo-ish way to get now in
a database-compatible format, so it is more easily testable.
@sbidoul sbidoul force-pushed the 8.0-jobrunner-sbi branch from 7d64a30 to 24f54e0 Compare May 14, 2015 20:20
@sbidoul
Copy link
Member Author
sbidoul commented May 15, 2015

I rebased to get the latest travis config.

There are 3 todo's left, which IMO can be left for future work:

  • better mechanism to http get asynchronously: normally not a real performance issue, but in case it is perhaps using a threadpool would be a solution
  • detect databases on which connector is added/removed: currently the server needs to be restarted in such case, which should not be an issue except for multi-tenant hosters
  • finalize sequential channels (needs thinking around ETA), so I did not document that feature

So from my point of view it's ready to merge if and when Travis manages to gives back a green status.

@guewen
Copy link
Member
guewen commented May 15, 2015

I took the liberty to add Acsone in the list of maintainers next to Akretion as I thought this contrib together with Laurent's previous work justifies it but I don't know the volume of Akretion contribs. If you feel this is not appropriate let me know.

Absolutely deserved.

supports job channels. You should try the job runner first
and fall back to using workers in case the runner does not
work (sic) for you, in which case we will very much appreciate
a github issue describing the problems you encoutered.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/encoutered/encountered/

@guewen
Copy link
Member
guewen commented May 15, 2015

I spotted 2 very little things in the doc (inline comments), apart that, all good!

@lmignon
Copy link
Contributor
lmignon commented May 15, 2015

I'm really impressed by this PR and the educational aspects of the doctects associated to each new concept. The connector module is one of my favorite OCA addons and a killer feature for Odoo/OCA. IMO it's ready to be merged. 👍

@guewen
Copy link
Member
guewen commented May 15, 2015

I'm really impressed by this PR and the educational aspects of the doctects associated to each new concept. The connector module is one of my favorite OCA addons and a killer feature for Odoo/OCA. IMO it's ready to be merged. 👍

I can't express it better. Many thanks for this contribution.

guewen added a commit that referenced this pull request May 15, 2015
@guewen guewen merged commit 499be9c into OCA:8.0 May 15, 2015
@sbidoul
Copy link
Member Author
sbidoul commented May 15, 2015

Cool. Thanks guys!

@agb80
Copy link
Member
agb80 commented Jun 19, 2015

@sbidoul is this runner available on 7.0 branch?

@sbidoul
Copy link
Member Author
sbidoul commented Jun 20, 2015

@agb80 yes, #53 is merged in 7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0