@@ -8403,21 +8403,22 @@ class Trigger(Prim):
8403
8403
Implements the Storm API for a Trigger.
8404
8404
'''
8405
8405
_storm_locals = (
8406
- {'name' : 'iden' , 'desc' : 'The Trigger iden.' , 'type' : 'str' , },
8407
- {'name' : 'set' , 'desc' : 'Set information in the Trigger.' ,
8408
- 'type' : {'type' : 'function' , '_funcname' : 'set' ,
8409
- 'args' : (
8410
- {'name' : 'name' , 'type' : 'str' , 'desc' : 'Name of the key to set.' , },
8411
- {'name' : 'valu' , 'type' : 'prim' , 'desc' : 'The data to set' , }
8412
- ),
8413
- 'returns' : {'type' : 'null' , }}},
8414
- {'name' : 'move' , 'desc' : 'Modify the Trigger to run in a different View.' ,
8415
- 'type' : {'type' : 'function' , '_funcname' : 'move' ,
8416
- 'args' : (
8417
- {'name' : 'viewiden' , 'type' : 'str' ,
8418
- 'desc' : 'The iden of the new View for the Trigger to run in.' , },
8419
- ),
8420
- 'returns' : {'type' : 'null' , }}},
8406
+ {'name' : 'async' , 'desc' : 'Whether the Trigger runs asynchronously.' , 'type' : 'boolean' },
8407
+ {'name' : 'cond' , 'desc' : 'The edit type which causes the Trigger to fire.' , 'type' : 'str' },
8408
+ {'name' : 'created' , 'desc' : 'The timestamp when the Trigger was created.' , 'type' : 'int' },
8409
+ {'name' : 'creator' , 'desc' : 'The iden of the user that created the Trigger.' , 'type' : 'str' },
8410
+ {'name' : 'doc' , 'desc' : 'The description of the Trigger.' , 'type' : 'str' },
8411
+ {'name' : 'enabled' , 'desc' : 'Whether the Trigger is enabled.' , 'type' : 'boolean' },
8412
+ {'name' : 'form' , 'desc' : 'The form which causes the Trigger to fire.' , 'type' : 'str' },
8413
+ {'name' : 'iden' , 'desc' : 'The Trigger iden.' , 'type' : 'str' },
8414
+ {'name' : 'n2form' , 'desc' : 'The N2 form which causes the Trigger to fire.' , 'type' : 'str' },
8415
+ {'name' : 'name' , 'desc' : 'The name of the Trigger.' , 'type' : 'str' },
8416
+ {'name' : 'prop' , 'desc' : 'The prop which causes the Trigger to fire.' , 'type' : 'str' },
8417
+ {'name' : 'storm' , 'desc' : 'The Storm query that the Trigger runs.' , 'type' : 'str' },
8418
+ {'name' : 'tag' , 'desc' : 'The tag which causes the Trigger to fire.' , 'type' : 'str' },
8419
+ {'name' : 'user' , 'desc' : 'The iden of the user the Trigger runs as.' , 'type' : 'str' },
8420
+ {'name' : 'verb' , 'desc' : 'The edge verb which causes the Trigger to fire.' , 'type' : 'str' },
8421
+ {'name' : 'view' , 'desc' : 'The iden of the view the Trigger runs in.' , 'type' : 'str' },
8421
8422
)
8422
8423
_storm_typename = 'trigger'
8423
8424
_ismutable = False
@@ -8426,62 +8427,44 @@ def __init__(self, runt, tdef):
8426
8427
8427
8428
Prim .__init__ (self , tdef )
8428
8429
self .runt = runt
8429
-
8430
8430
self .locls .update (self .getObjLocals ())
8431
- self .locls ['iden' ] = self .valu .get ('iden' )
8432
8431
8433
8432
def __hash__ (self ):
8434
- return hash ((self ._storm_typename , self .locls ['iden' ]))
8435
-
8436
- def getObjLocals (self ):
8437
- return {
8438
- 'set' : self .set ,
8439
- 'move' : self .move ,
8440
- }
8433
+ return hash ((self ._storm_typename , self .valu .get ('iden' )))
8441
8434
8442
8435
def value (self ):
8443
8436
return copy .deepcopy (self .valu )
8444
8437
8445
8438
async def deref (self , name ):
8446
8439
name = await tostr (name )
8440
+ return self .valu .get (name )
8447
8441
8448
- valu = self .valu .get (name , s_common .novalu )
8449
- if valu is not s_common .novalu :
8450
- return valu
8451
-
8452
- return self .locls .get (name )
8453
-
8454
- async def set (self , name , valu ):
8455
- trigiden = self .valu .get ('iden' )
8442
+ async def setitem (self , name , valu ):
8456
8443
viewiden = self .valu .get ('view' )
8457
8444
8458
- view = self .runt .view .core .reqView (viewiden )
8459
-
8460
8445
name = await tostr (name )
8461
- if name in ('async' , 'enabled' , ):
8446
+ if name in ('async' , 'enabled' ):
8462
8447
valu = await tobool (valu )
8463
- if name in ('user' , 'doc' , 'name' , 'storm' , ):
8448
+ elif name in ('user' , 'doc' , 'name' , 'storm' , 'view' ):
8464
8449
valu = await tostr (valu )
8465
8450
8466
- if name == 'user' :
8451
+ if name == 'view' :
8452
+ return await self ._move (valu )
8453
+ elif name == 'user' :
8467
8454
self .runt .confirm (('trigger' , 'set' , 'user' ))
8468
8455
else :
8469
8456
self .runt .confirm (('trigger' , 'set' , name ), gateiden = viewiden )
8470
8457
8471
- await view .setTriggerInfo (trigiden , name , valu )
8458
+ view = self .runt .view .core .reqView (viewiden )
8459
+ await view .setTriggerInfo (self .valu .get ('iden' ), name , valu )
8472
8460
8473
8461
self .valu [name ] = valu
8474
8462
8475
8463
return self
8476
8464
8477
- async def move (self , viewiden ):
8465
+ async def _move (self , viewiden ):
8478
8466
trigiden = self .valu .get ('iden' )
8479
- viewiden = await tostr (viewiden )
8480
-
8481
- todo = s_common .todo ('getViewDef' , viewiden )
8482
- vdef = await self .runt .dyncall ('cortex' , todo )
8483
- if vdef is None :
8484
- raise s_exc .NoSuchView (mesg = f'No view with iden={ viewiden } ' , iden = viewiden )
8467
+ view = self .runt .view .core .reqView (viewiden )
8485
8468
8486
8469
trigview = self .valu .get ('view' )
8487
8470
self .runt .confirm (('view' , 'read' ), gateiden = viewiden )
@@ -9103,6 +9086,10 @@ async def _methCronAdd(self, **kwargs):
9103
9086
view = self .runt .view .iden
9104
9087
cdef ['view' ] = view
9105
9088
9089
+ for argname in ('name' , 'doc' ):
9090
+ if (valu := kwargs .get (argname )) is not None :
9091
+ cdef [argname ] = await tostr (valu )
9092
+
9106
9093
todo = s_common .todo ('addCronJob' , cdef )
9107
9094
gatekeys = ((self .runt .user .iden , ('cron' , 'add' ), view ),)
9108
9095
cdef = await self .dyncall ('cortex' , todo , gatekeys = gatekeys )
@@ -9226,21 +9213,17 @@ class CronJob(Prim):
9226
9213
Implements the Storm api for a cronjob instance.
9227
9214
'''
9228
9215
_storm_locals = (
9229
- {'name' : 'iden' , 'desc' : 'The iden of the Cron Job.' , 'type' : 'str' , },
9230
- {'name' : 'set' , 'desc' : '''
9231
- Set an editable field in the cron job definition.
9232
-
9233
- Example:
9234
- Change the name of a cron job::
9235
-
9236
- $lib.cron.get($iden).set(name, "foo bar cron job")''' ,
9237
- 'type' : {'type' : 'function' , '_funcname' : '_methCronJobSet' ,
9238
- 'args' : (
9239
- {'name' : 'name' , 'type' : 'str' , 'desc' : 'The name of the field being set' , },
9240
- {'name' : 'valu' , 'type' : 'any' , 'desc' : 'The value to set on the definition.' , },
9241
- ),
9242
- 'returns' : {'type' : 'cronjob' , 'desc' : 'The ``cronjob``' , }}},
9243
-
9216
+ {'name' : 'completed' , 'desc' : 'True if a non-recurring Cron Job has completed.' , 'type' : 'boolean' },
9217
+ {'name' : 'creator' , 'desc' : 'The iden of the user that created the Cron Job.' , 'type' : 'str' },
9218
+ {'name' : 'created' , 'desc' : 'The timestamp when the Cron Job was created.' , 'type' : 'int' },
9219
+ {'name' : 'doc' , 'desc' : 'The description of the Cron Job.' , 'type' : 'str' },
9220
+ {'name' : 'enabled' , 'desc' : 'Whether the Cron Job is enabled.' , 'type' : 'boolean' },
9221
+ {'name' : 'iden' , 'desc' : 'The iden of the Cron Job.' , 'type' : 'str' },
9222
+ {'name' : 'name' , 'desc' : 'The name of the Cron Job.' , 'type' : 'str' },
9223
+ {'name' : 'pool' , 'desc' : 'Whether the Cron Job will offload the query to a Storm pool.' , 'type' : 'boolean' },
9224
+ {'name' : 'storm' , 'desc' : 'The Storm query the Cron Job runs.' , 'type' : 'str' },
9225
+ {'name' : 'view' , 'desc' : 'The iden of the view the Cron Job runs in.' , 'type' : 'str' },
9226
+ {'name' : 'user' , 'desc' : 'The iden of the user the Cron Job runs as.' , 'type' : 'str' },
9244
9227
{'name' : 'kill' , 'desc' : 'If the job is currently running, terminate the task.' ,
9245
9228
'type' : {'type' : 'function' , '_funcname' : '_methCronJobKill' ,
9246
9229
'returns' : {'type' : 'boolean' , 'desc' : 'A boolean value which is true if the task was terminated.' }}},
@@ -9250,10 +9233,6 @@ class CronJob(Prim):
9250
9233
'returns' :
9251
9234
{'type' : 'dict' ,
9252
9235
'desc' : 'A dictionary containing structured data about a cronjob for display purposes.' }}},
9253
-
9254
- {'name' : 'completed' , 'desc' : 'True if a non-recurring Cron Job has completed.' ,
9255
- 'type' : {'type' : 'gtor' , '_gtorfunc' : '_gtorCompleted' , 'returns' : {'type' : 'boolean' }}},
9256
-
9257
9236
)
9258
9237
_storm_typename = 'cronjob'
9259
9238
_ismutable = False
@@ -9262,15 +9241,12 @@ def __init__(self, runt, cdef, path=None):
9262
9241
Prim .__init__ (self , cdef , path = path )
9263
9242
self .runt = runt
9264
9243
self .locls .update (self .getObjLocals ())
9265
- self .locls ['iden' ] = self .valu .get ('iden' )
9266
- self .gtors ['completed' ] = self ._gtorCompleted
9267
9244
9268
9245
def __hash__ (self ):
9269
- return hash ((self ._storm_typename , self .locls [ 'iden' ] ))
9246
+ return hash ((self ._storm_typename , self .valu . get ( 'iden' ) ))
9270
9247
9271
9248
def getObjLocals (self ):
9272
9249
return {
9273
- 'set' : self ._methCronJobSet ,
9274
9250
'kill' : self ._methCronJobKill ,
9275
9251
'pprint' : self ._methCronJobPprint ,
9276
9252
}
@@ -9280,7 +9256,7 @@ async def _methCronJobKill(self):
9280
9256
self .runt .confirm (('cron' , 'kill' ), gateiden = iden )
9281
9257
return await self .runt .view .core .killCronTask (iden )
9282
9258
9283
- async def _methCronJobSet (self , name , valu ):
9259
+ async def setitem (self , name , valu ):
9284
9260
name = await tostr (name )
9285
9261
valu = await toprim (valu )
9286
9262
iden = self .valu .get ('iden' )
@@ -9297,10 +9273,13 @@ async def _methCronJobSet(self, name, valu):
9297
9273
return self
9298
9274
9299
9275
@stormfunc (readonly = True )
9300
- async def _gtorCompleted (self ):
9301
- if self .valu .get ('recs' ):
9302
- return False
9303
- return True
9276
+ async def _derefGet (self , name ):
9277
+ name = await tostr (name )
9278
+
9279
+ if name == 'completed' :
9280
+ return not bool (self .valu .get ('recs' ))
9281
+
9282
+ return copy .deepcopy (self .valu .get (name ))
9304
9283
9305
9284
def value (self ):
9306
9285
return copy .deepcopy (self .valu )
0 commit comments