本文整理汇总了Python中socorro.external.postgresql.dbapi2_util.single_value_sql函数的典型用法代码示例。如果您正苦于以下问题:Python single_value_sql函数的具体用法?Python single_value_sql怎么用?Python single_value_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了single_value_sql函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _assume_identity_by_host
def _assume_identity_by_host(self, connection, threshold, hostname,
req_id):
"""This function implements the case where a newly registering
processor wants to take over for a dead processor with the same host
name as the registering processor.
Parameters:
connection - a connection object
threshold - a datetime instance that represents an absolute date
made from the current datetime minus the timedelta
that defines how often a processor must update its
registration. If the threshold is greater than the
'lastseendatetime' of a registered processor, that
processor is considered dead.
hostname - the name of the host of the registering processor.
req_id - not used by this method, but present to meet the required
api for a registration method.
Returns:
an integer representing the new id of the newly registered
processor."""
self.config.logger.debug(
"looking for a dead processor for host %s",
hostname
)
try:
sql = ("select id from processors"
" where lastseendatetime < %s"
" and name like %s limit 1")
hostname_phrase = hostname + '%'
processor_id = single_value_sql(
connection,
sql,
(threshold, hostname_phrase)
)
self.config.logger.info(
"will step in for processor %s",
processor_id
)
# a dead processor for this host was found
self._take_over_dead_processor(connection, processor_id)
return processor_id
except SQLDidNotReturnSingleValue:
# no dead processor was found for this host, is there already
# a live processor for it?
self.config.logger.debug("no dead processor found for host, %s",
hostname)
try:
sql = ("select id from processors"
" where name like '%s%%'" % hostname)
self.processor_id = single_value_sql(connection, sql)
message = ('a live processor already exists for host %s' %
hostname)
# there was a live processor found for this host, we cannot
# complete registration
raise RegistrationError(message)
except SQLDidNotReturnSingleValue:
# there was no processor for this host was found, make new one
return self._assume_new_identity(connection, threshold,
hostname, req_id)
开发者ID:erikrose,项目名称:socorro,代码行数:59,代码来源:registration_client.py
示例2: _prioritize_previously_enqueued_jobs_transaction
def _prioritize_previously_enqueued_jobs_transaction(self, connection,
crash_id):
"""priorty jobs come into the system at random times. A given crash_id
may already be queued for processing when a priority request comes in
for it. To avoid repeating processing, a priority crash_id is checked
to see if it is already queued. If it is, the processor already
assigned to it is told to expedite processing. This done just by
entering the crash_id into the processors private 'priority_jobs_XXX'
table."""
try:
job_owner = single_value_sql(
connection,
"select owner from jobs where uuid = %s",
(crash_id,)
)
except SQLDidNotReturnSingleValue:
return False
priority_job_table_name = 'priority_jobs_%d' % job_owner
self.config.logger.debug(
"priority job %s was already in the queue, assigned to %d",
crash_id,
job_owner
)
try:
# detect if the found job was assigned to a processor that was
# dead by checking to see if the priority jobs table exists or
# not. If id doesn't exist, wait for the job to get reassigned
# to a live processor. It in the future, it may be better to
# just reassign the job immediately.
single_value_sql( # return value intentionally ignored
connection,
"select 1 from pg_stat_user_tables where relname = %s",
(priority_job_table_name,)
)
except SQLDidNotReturnSingleValue:
self.config.logger.debug(
"%s assigned to dead processor %d - "
"wait for reassignment",
crash_id,
job_owner
)
# likely that the job is assigned to a dead processor
# skip processing it this time around - by next time
# hopefully it will have been
# re assigned to a live processor
return False
execute_no_results(
connection,
"insert into %s (uuid) values (%%s)" %
priority_job_table_name,
(crash_id,)
)
execute_no_results(
connection,
"delete from priorityjobs where uuid = %s",
(crash_id,)
)
return True
开发者ID:aerenchyma,项目名称:socorro,代码行数:58,代码来源:monitor_app.py
示例3: _save_plugins
def _save_plugins(self, connection, processed_crash, report_id):
""" Electrolysis Support - Optional - processed_crash may contain a
ProcessType of plugin. In the future this value would be default,
content, maybe even Jetpack... This indicates which process was the
crashing process.
plugin - When set to plugin, the jsonDocument MUST calso contain
PluginFilename, PluginName, and PluginVersion
"""
process_type = processed_crash['process_type']
if not process_type:
return
if process_type == "plugin":
# Bug#543776 We actually will are relaxing the non-null policy...
# a null filename, name, and version is OK. We'll use empty strings
try:
plugin_filename = processed_crash['PluginFilename']
plugin_name = processed_crash['PluginName']
plugin_version = processed_crash['PluginVersion']
except KeyError, x:
self.config.logger.error(
'the crash is missing a required field: %s', str(x)
)
return
find_plugin_sql = ('select id from plugins '
'where filename = %s '
'and name = %s')
try:
plugin_id = single_value_sql(connection,
find_plugin_sql,
(plugin_filename,
plugin_name))
except SQLDidNotReturnSingleValue:
insert_plugsins_sql = ("insert into plugins (filename, name) "
"values (%s, %s) returning id")
plugin_id = single_value_sql(connection,
insert_plugsins_sql,
(plugin_filename,
plugin_name))
crash_id = processed_crash['uuid']
table_suffix = self._table_suffix_for_crash_id(crash_id)
plugin_reports_table_name = 'plugins_reports_%s' % table_suffix
plugins_reports_insert_sql = (
'insert into %s '
' (report_id, plugin_id, date_processed, version) '
'values '
' (%%s, %%s, %%s, %%s)' % plugin_reports_table_name
)
values_tuple = (report_id,
plugin_id,
processed_crash['date_processed'],
plugin_version)
execute_no_results(connection,
plugins_reports_insert_sql,
values_tuple)
开发者ID:ajsb85,项目名称:socorro,代码行数:56,代码来源:crashstorage.py
示例4: test_single_value_sql2
def test_single_value_sql2(self):
m_execute = Mock()
m_fetchall = Mock(return_value=((17,),))
m_cursor = Mock()
m_cursor.execute = m_execute
m_cursor.fetchall = m_fetchall
conn = Mock()
conn.cursor.return_value = m_cursor
dbapi2_util.single_value_sql(conn, "select 17", (1, 2, 3))
eq_(conn.cursor.call_count, 1)
eq_(m_cursor.execute.call_count, 1)
m_cursor.execute.assert_called_once_with('select 17', (1, 2, 3))
开发者ID:Earth4,项目名称:socorro,代码行数:13,代码来源:test_dbapi2_util.py
示例5: _save_processed_report
def _save_processed_report(self, connection, processed_crash):
column_list = []
placeholder_list = []
value_list = []
for pro_crash_name, report_name in self._reports_table_mappings:
column_list.append(report_name)
placeholder_list.append('%s')
value_list.append(processed_crash[pro_crash_name])
crash_id = processed_crash['uuid']
reports_table_name = (
'reports_%s' % self._table_suffix_for_crash_id(crash_id)
)
insert_sql = "insert into %s (%s) values (%s) returning id" % (
reports_table_name,
', '.join(column_list),
', '.join(placeholder_list)
)
# we want to insert directly into the report table. There is a
# chance however that the record already exists. If it does, then
# the insert would fail and the connection fall into a "broken" state.
# To avoid this, we set a savepoint to which we can roll back if the
# record already exists - essentially a nested transaction.
# We use the name of the executing thread as the savepoint name.
# alternatively we could get a uuid.
savepoint_name = threading.currentThread().getName().replace('-', '')
execute_no_results(connection, "savepoint %s" % savepoint_name)
try:
report_id = single_value_sql(connection, insert_sql, value_list)
execute_no_results(
connection,
"release savepoint %s" % savepoint_name
)
except self.config.database_class.IntegrityError:
# report already exists
execute_no_results(
connection,
"rollback to savepoint %s" % savepoint_name
)
execute_no_results(
connection,
"release savepoint %s" % savepoint_name
)
execute_no_results(
connection,
"delete from %s where uuid = %%s" % reports_table_name,
(processed_crash.uuid,)
)
report_id = single_value_sql(connection, insert_sql, value_list)
return report_id
开发者ID:ajsb85,项目名称:socorro,代码行数:49,代码来源:crashstorage.py
示例6: test_single_value_sql3
def test_single_value_sql3(self):
m_execute = Mock()
m_fetchall = Mock(return_value=None)
m_cursor = MagicMock()
m_cursor.execute = m_execute
m_cursor.fetchall = m_fetchall
conn = MagicMock()
conn.cursor.return_value.__enter__.return_value = m_cursor
with pytest.raises(dbapi2_util.SQLDidNotReturnSingleValue):
dbapi2_util.single_value_sql(conn, 'select 17', (1, 2, 3))
assert conn.cursor.call_count == 1
assert m_cursor.execute.call_count == 1
m_cursor.execute.assert_called_once_with('select 17', (1, 2, 3))
开发者ID:stephendonner,项目名称:socorro,代码行数:15,代码来源:test_dbapi2_util.py
示例7: _assume_new_identity
def _assume_new_identity(self, connection, threshold, hostname, req_id):
"""This function implements the method of registering a brand new
processor. It will cause a new row to be entered into the 'processors'
table within the database.
Parameters:
cursor - a cursor object
threshold - not used by this method, but present to meet the
required api for a registration method.
hostname - the name of the host of the registering processor.
not used by the method, but present to meet the
required api for a registration method.
req_id - not used by this method, but present to meet the required
api for a registration method.
Returns:
an integer representing the new id of the newly registered
processor."""
self.config.logger.debug("becoming a new processor")
return single_value_sql(
connection,
"insert into processors"
" (id,"
" name,"
" startdatetime,"
" lastseendatetime) "
"values"
" (default,"
" %s,"
" now(),"
" now()) "
"returning id",
(self.processor_name,),
)
开发者ID:rfw,项目名称:socorro,代码行数:33,代码来源:registration_client.py
示例8: _assume_specific_identity
def _assume_specific_identity(self, connection, threshold, hostname, req_id):
"""This function implements the case where we want the processor to
take over for a specific existing but dead processor without regard
to what host the dead processor was running on. If the dead processor
was not found, or the processor was not really dead, the function will
raise a RegistrationError and decline to register the new processor.
Parameters:
connection - a connection object
threshold - a datetime instance that represents an absolute date
made from the current datetime minus the timedelta
that defines how often a processor must update its
registration. If the threshold is greater than the
'lastseendatetime' of a registered processor, that
processor is considered dead.
hostname - the name of the host of the registering processor.
not used by the method, but present to meet the
required api for a registration method.
req_id - an integer representing the 'id' (from the 'id' column of
'processors' database table) of the allegedly dead
processor.
Returns:
an integer representing the new id of the newly registered
processor."""
self.config.logger.debug("looking for a specific dead processor")
try:
check_sql = "select id from processors " "where lastSeenDateTime < %s " "and id = %s"
processor_id = single_value_sql(connection, check_sql, (threshold, req_id))
self.config.logger.info("stepping in for processor %s", processor_id)
self._take_over_dead_processor(connection, processor_id)
return processor_id
except SQLDidNotReturnSingleValue:
raise RegistrationError("%s doesn't exist or is not dead" % req_id)
开发者ID:rfw,项目名称:socorro,代码行数:34,代码来源:registration_client.py
示例9: _assume_any_identity
def _assume_any_identity(self, connection, threshold, hostname, req_id):
"""This function implements the case where we're interested in taking
over for any dead processor regardless of what host it was running on.
Parameters:
connection - a connection object
threshold - a datetime instance that represents an absolute date
made from the current datetime minus the timedelta
that defines how often a processor must update its
registration. If the threshold is greater than the
'lastseendatetime' of a registered processor, that
processor is considered dead.
hostname - the name of the host of the registering processor.
not used by the method, but present to meet the
required api for a registration method.
req_id - not used by this method, but present to meet the required
api for a registration method.
Returns:
an integer representing the new id of the newly registered
processor."""
self.config.logger.debug("looking for any dead processor")
try:
sql = "select id from processors" " where lastseendatetime < %s limit 1"
processor_id = single_value_sql(connection, sql, (threshold,))
self.config.logger.info("will step in for processor %s", processor_id)
self._take_over_dead_processor(connection, processor_id)
return processor_id
except SQLDidNotReturnSingleValue:
self.config.logger.debug("no dead processor found, registering as new")
return self._assume_new_identity(connection, threshold, hostname, req_id)
开发者ID:rfw,项目名称:socorro,代码行数:30,代码来源:registration_client.py
示例10: _force_assume_identity_by_host
def _force_assume_identity_by_host(self, connection, threshold, hostname, req_id):
"""This function implements the case where a newly registering
processor wants to take over for a processor with the same host
name as the registering processor. This is the case where the
existing processor is likely dead but didn't manage to halt cleanly.
Parameters:
connection - a connection object
threshold - a datetime instance that represents an absolute date
made from the current datetime minus the timedelta
that defines how often a processor must update its
registration. If the threshold is greater than the
'lastseendatetime' of a registered processor, that
processor is considered dead.
hostname - the name of the host of the registering processor.
req_id - not used by this method, but present to meet the required
api for a registration method.
Returns:
an integer representing the new id of the newly registered
processor."""
self.config.logger.debug("looking for a processor for host %s", hostname)
try:
sql = "select id from processors" " where name like %s limit 1"
hostname_phrase = hostname + "%"
processor_id = single_value_sql(connection, sql, (hostname_phrase,))
self.config.logger.info("will take over processor %s", processor_id)
# a processor for this host was found
self._take_over_dead_processor(connection, processor_id)
return processor_id
except SQLDidNotReturnSingleValue:
return self._assume_new_identity(connection, threshold, hostname, req_id)
开发者ID:rfw,项目名称:socorro,代码行数:31,代码来源:registration_client.py
示例11: _get_processed_crash_transaction
def _get_processed_crash_transaction(self, connection, crash_id):
fetch_sql = (
'select processed_crash from processed_crashes where uuid = %s'
)
try:
return single_value_sql(connection, fetch_sql, (crash_id,))
except SQLDidNotReturnSingleValue:
raise CrashIDNotFound(crash_id)
开发者ID:Tchanders,项目名称:socorro,代码行数:8,代码来源:crash_migration_app.py
示例12: _get_raw_crash_transaction
def _get_raw_crash_transaction(self, connection, crash_id):
raw_crash_table_name = (
'raw_crash_%s' % self._table_suffix_for_crash_id(crash_id)
)
fetch_sql = 'select raw_crash from %s where uuid = %ss' % \
raw_crash_table_name
try:
return single_value_sql(connection, fetch_sql, (crash_id,))
except SQLDidNotReturnSingleValue:
raise CrashIDNotFound(crash_id)
开发者ID:gurjeet,项目名称:socorro,代码行数:10,代码来源:crashstorage.py
示例13: _load_from_postgres
def _load_from_postgres(self, connection, file_path):
try:
json_dump = single_value_sql(
connection,
'SELECT state FROM crontabber_state'
)
if json_dump != '{}':
with open(file_path, 'w') as f:
f.write(json_dump)
except SQLDidNotReturnSingleValue:
pass
开发者ID:pkucoin,项目名称:socorro,代码行数:11,代码来源:crontabber.py
示例14: _create_priority_jobs
def _create_priority_jobs(self, connection):
self.processor_id = single_value_sql(
connection, "select id from processors where name = %s", (self.processor_name,)
)
priority_jobs_table_name = "priority_jobs_%d" % self.processor_id
execute_no_results(connection, "drop table if exists %s" % priority_jobs_table_name)
execute_no_results(
connection, "create table %s (uuid varchar(50) not null primary key)" % priority_jobs_table_name
)
self.config.logger.info("created priority jobs table: %s", priority_jobs_table_name)
return priority_jobs_table_name
开发者ID:rfw,项目名称:socorro,代码行数:11,代码来源:legacy_new_crash_source.py
示例15: __delitem__
def __delitem__(self, connection, key):
"""remove the item by key or raise KeyError"""
try:
# result intentionally ignored
single_value_sql(
connection,
"""SELECT app_name
FROM crontabber
WHERE
app_name = %s""",
(key,)
)
except SQLDidNotReturnSingleValue:
raise KeyError(key)
# item exists
execute_no_results(
connection,
"""DELETE FROM crontabber
WHERE app_name = %s""",
(key,)
)
开发者ID:pkucoin,项目名称:socorro,代码行数:21,代码来源:crontabber.py
示例16: _get_processed_crash_transaction
def _get_processed_crash_transaction(self, connection, crash_id):
processed_crash_table_name = (
'processed_crashes_%s' % self._table_suffix_for_crash_id(crash_id)
)
fetch_sql = 'select processed_crash from %s where uuid = %%s' % \
processed_crash_table_name
try:
return single_value_sql(connection, fetch_sql, (crash_id,))
except ProgrammingError, e:
err = 'relation "%s" does not exist' % processed_crash_table_name
if err in str(e):
raise CrashIDNotFound(crash_id)
raise
开发者ID:nnethercote,项目名称:socorro,代码行数:13,代码来源:crashstorage.py
示例17: test_single_value_sql1
def test_single_value_sql1(self):
m_execute = Mock()
m_fetchall = Mock(return_value=((17,),))
m_cursor = MagicMock()
m_cursor.execute = m_execute
m_cursor.fetchall = m_fetchall
conn = MagicMock()
conn.cursor.return_value.__enter__.return_value = m_cursor
r = dbapi2_util.single_value_sql(conn, "select 17")
eq_(r, 17)
eq_(conn.cursor.call_count, 1)
eq_(m_cursor.execute.call_count, 1)
m_cursor.execute.assert_called_once_with('select 17', None)
开发者ID:snorp,项目名称:socorro,代码行数:14,代码来源:test_dbapi2_util.py
示例18: _get_raw_crash_transaction
def _get_raw_crash_transaction(self, connection, crash_id):
raw_crash_table_name = (
'raw_crashes_%s' % self._table_suffix_for_crash_id(crash_id)
)
fetch_sql = 'select raw_crash from %s where uuid = %%s' % \
raw_crash_table_name
try:
return single_value_sql(connection, fetch_sql, (crash_id,))
except ProgrammingError as e:
err = 'relation "%s" does not exist' % raw_crash_table_name
if err in str(e):
raise CrashIDNotFound(crash_id)
raise
except SQLDidNotReturnSingleValue:
raise CrashIDNotFound(crash_id)
开发者ID:m8ttyB,项目名称:socorro,代码行数:15,代码来源:crashstorage.py
示例19: edit_featured_versions
def edit_featured_versions(self, connection, product, versions):
sql = """
SELECT
edit_featured_versions(%s, {})
""".format(','.join('%s' for _ in versions))
worked = single_value_sql(
connection,
sql,
[product] + versions
)
if worked:
self.config.logger.info(
'Set featured versions for %s %r' % (
product,
versions
)
)
else:
self.config.logger.warning(
'Unable to set featured versions for %s %r' % (
product,
versions
)
)
开发者ID:snorp,项目名称:socorro,代码行数:24,代码来源:featured_versions_sync.py
示例20: __setitem__
def __setitem__(self, connection, key, value):
class LastErrorEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, type):
return repr(obj)
return json.JSONEncoder.default(self, obj)
try:
single_value_sql(
connection,
"""SELECT app_name
FROM crontabber
WHERE
app_name = %s""",
(key,)
)
# the key exists, do an update
next_sql = """UPDATE crontabber
SET
next_run = %(next_run)s,
first_run = %(first_run)s,
last_run = %(last_run)s,
last_success = %(last_success)s,
depends_on = %(depends_on)s,
error_count = %(error_count)s,
last_error = %(last_error)s
WHERE
app_name = %(app_name)s"""
except SQLDidNotReturnSingleValue:
# the key does not exist, do an insert
next_sql = """
INSERT INTO crontabber (
app_name,
next_run,
first_run,
last_run,
last_success,
depends_on,
error_count,
last_error
) VALUES (
%(app_name)s,
%(next_run)s,
%(first_run)s,
%(last_run)s,
%(last_success)s,
%(depends_on)s,
%(error_count)s,
%(last_error)s
)"""
parameters = {
'app_name': key,
'next_run': value['next_run'],
'first_run': value['first_run'],
'last_run': value['last_run'],
'last_success': value.get('last_success'),
'depends_on': value['depends_on'],
'error_count': value['error_count'],
'last_error': json.dumps(value['last_error'], cls=LastErrorEncoder)
}
execute_no_results(
connection,
next_sql,
parameters
)
开发者ID:pkucoin,项目名称:socorro,代码行数:65,代码来源:crontabber.py
注:本文中的socorro.external.postgresql.dbapi2_util.single_value_sql函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论