mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add a user_id column to the job table. This is necessary to decouple jobs from sessions, which is required for the forthcoming API.
This commit is contained in:
@@ -277,6 +277,7 @@ class JobWrapper( object ):
|
||||
def __init__(self, job, tool, queue ):
|
||||
self.job_id = job.id
|
||||
self.session_id = job.session_id
|
||||
self.user_id = job.user_id
|
||||
self.tool = tool
|
||||
self.queue = queue
|
||||
self.app = queue.app
|
||||
|
||||
@@ -101,6 +101,7 @@ class Job( object ):
|
||||
DELETED = 'deleted' )
|
||||
def __init__( self ):
|
||||
self.session_id = None
|
||||
self.user_id = None
|
||||
self.tool_id = None
|
||||
self.tool_version = None
|
||||
self.command_line = None
|
||||
|
||||
@@ -330,6 +330,7 @@ Job.table = Table( "job", metadata,
|
||||
Column( "stderr", TEXT ),
|
||||
Column( "traceback", TEXT ),
|
||||
Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True, nullable=True ),
|
||||
Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True ),
|
||||
Column( "job_runner_name", String( 255 ) ),
|
||||
Column( "job_runner_external_id", String( 255 ) ) )
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Add a user_id column to the job table.
|
||||
"""
|
||||
|
||||
from sqlalchemy import *
|
||||
from migrate import *
|
||||
from migrate.changeset import *
|
||||
from galaxy.model.custom_types import *
|
||||
|
||||
import datetime
|
||||
now = datetime.datetime.utcnow
|
||||
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
metadata = MetaData( migrate_engine )
|
||||
|
||||
def upgrade():
|
||||
print __doc__
|
||||
metadata.reflect()
|
||||
try:
|
||||
Job_table = Table( "job", metadata, autoload=True )
|
||||
except NoSuchTableError:
|
||||
Job_table = None
|
||||
log.error( "Failed loading table job" )
|
||||
if Job_table:
|
||||
try:
|
||||
col = Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=True )
|
||||
col.create( Job_table )
|
||||
assert col is Job_table.c.user_id
|
||||
except Exception, e:
|
||||
log.error( "Adding column 'user_id' to job table failed: %s" % ( str( e ) ) )
|
||||
try:
|
||||
i = Index( "ix_job_user_id", Job_table.c.user_id )
|
||||
i.create()
|
||||
except Exception, e:
|
||||
log.error( "Adding index 'ix_job_user_id' failed: %s" % str( e ) )
|
||||
|
||||
def downgrade():
|
||||
metadata.reflect()
|
||||
try:
|
||||
Job_table = Table( "job", metadata, autoload=True )
|
||||
except NoSuchTableError:
|
||||
Job_table = None
|
||||
log.error( "Failed loading table job" )
|
||||
if Job_table:
|
||||
try:
|
||||
col = Job_table.c.user_id
|
||||
col.drop()
|
||||
except Exception, e:
|
||||
log.error( "Dropping column 'user_id' from job table failed: %s" % ( str( e ) ) )
|
||||
@@ -308,7 +308,12 @@ class DefaultToolAction( object ):
|
||||
trans.sa_session.flush()
|
||||
# Create the job object
|
||||
job = trans.app.model.Job()
|
||||
job.session_id = trans.get_galaxy_session().id
|
||||
galaxy_session = trans.get_galaxy_session().id
|
||||
# If we're submitting from the API, there won't be a session.
|
||||
if type( galaxy_session ) == trans.model.GalaxySession:
|
||||
job.session_id = galaxy_session.id
|
||||
if trans.user is not None:
|
||||
job.user_id = trans.user.id
|
||||
job.history_id = trans.history.id
|
||||
job.tool_id = tool.id
|
||||
try:
|
||||
|
||||
@@ -297,7 +297,11 @@ def create_job( trans, params, tool, json_file_path, data_list, folder=None, ret
|
||||
Create the upload job.
|
||||
"""
|
||||
job = trans.app.model.Job()
|
||||
job.session_id = trans.get_galaxy_session().id
|
||||
galaxy_session = trans.get_galaxy_session()
|
||||
if type( galaxy_session ) == trans.model.GalaxySession:
|
||||
job.session_id = galaxy_session.id
|
||||
if trans.user is not None:
|
||||
job.user_id = trans.user.id
|
||||
if folder:
|
||||
job.library_folder_id = folder.id
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user