@platforma-sdk/workflow-tengo 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tengo/lib/exec.lib.tengo +94 -4
- package/dist/tengo/lib/pframes.xsv.lib.tengo +16 -1
- package/dist/tengo/lib/smart.lib.tengo +68 -0
- package/dist/tengo/lib/workflow.bquery.lib.tengo +0 -1
- package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.aggregate.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
- package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
- package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
- package/package.json +1 -1
|
@@ -69,6 +69,7 @@ builder := func() {
|
|
|
69
69
|
assetInfos := {}
|
|
70
70
|
assetDescriptors := {}
|
|
71
71
|
assetRules := {}
|
|
72
|
+
assetCache := {}
|
|
72
73
|
|
|
73
74
|
stdout := "stdout.txt"
|
|
74
75
|
stderr := "stderr.txt"
|
|
@@ -184,7 +185,7 @@ builder := func() {
|
|
|
184
185
|
},
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
|
-
*
|
|
188
|
+
* Use cacheMillis, cacheSeconds, cacheMinutes, cacheHours and cacheDays to not make hidden mistakes in cache time ranges.
|
|
188
189
|
* Sets the cache time.
|
|
189
190
|
*
|
|
190
191
|
* @param time: duration - the cache time from 'times' library.
|
|
@@ -275,10 +276,18 @@ builder := func() {
|
|
|
275
276
|
* @param pathsInArchive: string[] - paths inside the archive to be extracted into destinationDir.
|
|
276
277
|
* Empty array means 'unpack full archive'.
|
|
277
278
|
*/
|
|
278
|
-
addAsset: func(asset, destinationDir, pathsInArchive) {
|
|
279
|
+
addAsset: func(asset, destinationDir, ...pathsInArchive) {
|
|
280
|
+
if (len(pathsInArchive) == 1 && is_array(pathsInArchive[0])) {
|
|
281
|
+
// support [<paths>] single argument
|
|
282
|
+
pathsInArchive = pathsInArchive[0]
|
|
283
|
+
}
|
|
284
|
+
if len(pathsInArchive) == 0 {
|
|
285
|
+
// default for 'no paths' is to extract all
|
|
286
|
+
pathsInArchive = []
|
|
287
|
+
}
|
|
288
|
+
|
|
279
289
|
ll.assert(assets.isAssetInfo(asset),
|
|
280
290
|
"exec.builder.addAsset: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
281
|
-
|
|
282
291
|
validation.assertJsonSchema(destinationDir, "string", "exec.builder.addAsset: <destinationDir> is not a string. It must be a path inside working directory")
|
|
283
292
|
validation.assertJsonSchema(pathsInArchive, ["string"], "exec.builder.addAsset: <pathsInArchive> must contain list of strings with paths inside archive")
|
|
284
293
|
|
|
@@ -300,6 +309,86 @@ builder := func() {
|
|
|
300
309
|
return self
|
|
301
310
|
},
|
|
302
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Set custom cache time for given asset. By default, cache time of 1 day is applied to all assets.
|
|
314
|
+
* This allows to customize cache time on per-asset basis
|
|
315
|
+
*/
|
|
316
|
+
cacheAssetMillis: func (asset, millis) {
|
|
317
|
+
ll.assert(assets.isAssetInfo(asset),
|
|
318
|
+
"exec.builder.cacheAssetMillis: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
319
|
+
ll.assert(is_int(millis),
|
|
320
|
+
"exec.builder.cacheAssetMillis: asset cache time must be a number of milliseconds.")
|
|
321
|
+
|
|
322
|
+
assetIdKey := ll.idToString(asset._id)
|
|
323
|
+
assetCache[assetIdKey] = millis * times.millisecond
|
|
324
|
+
|
|
325
|
+
return self
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Set custom cache time for given asset. By default, cache time of 1 day is applied to all assets.
|
|
330
|
+
* This allows to customize cache time on per-asset basis
|
|
331
|
+
*/
|
|
332
|
+
cacheAssetSeconds: func (asset, seconds) {
|
|
333
|
+
ll.assert(assets.isAssetInfo(asset),
|
|
334
|
+
"exec.builder.cacheAssetSeconds: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
335
|
+
ll.assert(is_int(seconds),
|
|
336
|
+
"exec.builder.cacheAssetSeconds: asset cache time must be a number of seconds.")
|
|
337
|
+
|
|
338
|
+
assetIdKey := ll.idToString(asset._id)
|
|
339
|
+
assetCache[assetIdKey] = seconds * times.second
|
|
340
|
+
|
|
341
|
+
return self
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Set custom cache time for given asset. By default, cache time of 1 day is applied to all assets.
|
|
346
|
+
* This allows to customize cache time on per-asset basis
|
|
347
|
+
*/
|
|
348
|
+
cacheAssetMinutes: func (asset, minutes) {
|
|
349
|
+
ll.assert(assets.isAssetInfo(asset),
|
|
350
|
+
"exec.builder.cacheAssetMinutes: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
351
|
+
ll.assert(is_int(minutes),
|
|
352
|
+
"exec.builder.cacheAssetMinutes: asset cache time must be a number of minutes.")
|
|
353
|
+
|
|
354
|
+
assetIdKey := ll.idToString(asset._id)
|
|
355
|
+
assetCache[assetIdKey] = minutes * times.minute
|
|
356
|
+
|
|
357
|
+
return self
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Set custom cache time for given asset. By default, cache time of 1 day is applied to all assets.
|
|
362
|
+
* This allows to customize cache time on per-asset basis
|
|
363
|
+
*/
|
|
364
|
+
cacheAssetHours: func (asset, hours) {
|
|
365
|
+
ll.assert(assets.isAssetInfo(asset),
|
|
366
|
+
"exec.builder.cacheAssetHours: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
367
|
+
ll.assert(is_int(hours),
|
|
368
|
+
"exec.builder.cacheAssetHours: asset cache time must be a number of hours.")
|
|
369
|
+
|
|
370
|
+
assetIdKey := ll.idToString(asset._id)
|
|
371
|
+
assetCache[assetIdKey] = hours * times.hour
|
|
372
|
+
|
|
373
|
+
return self
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Set custom cache time for given asset. By default, cache time of 1 day is applied to all assets.
|
|
378
|
+
* This allows to customize cache time on per-asset basis
|
|
379
|
+
*/
|
|
380
|
+
cacheAssetDays: func (asset, days) {
|
|
381
|
+
ll.assert(assets.isAssetInfo(asset),
|
|
382
|
+
"exec.builder.cacheAssetHours: <asset> parameter is not an asset info. Provide the value obtained from assets.importAsset() here")
|
|
383
|
+
ll.assert(is_int(days),
|
|
384
|
+
"exec.builder.cacheAssetHours: asset cache time must be a number of days.")
|
|
385
|
+
|
|
386
|
+
assetIdKey := ll.idToString(asset._id)
|
|
387
|
+
assetCache[assetIdKey] = days * 24 * times.hour
|
|
388
|
+
|
|
389
|
+
return self
|
|
390
|
+
},
|
|
391
|
+
|
|
303
392
|
/**
|
|
304
393
|
* Adds a file to the working directory
|
|
305
394
|
*
|
|
@@ -515,7 +604,8 @@ builder := func() {
|
|
|
515
604
|
wdProcessors: wdProcessors,
|
|
516
605
|
assets: smart.createMapResource(assetInfos),
|
|
517
606
|
assetDescriptors: assetDescriptors,
|
|
518
|
-
assetRules: assetRules
|
|
607
|
+
assetRules: assetRules,
|
|
608
|
+
assetCache: assetCache
|
|
519
609
|
}
|
|
520
610
|
|
|
521
611
|
if !is_undefined(soft) {
|
|
@@ -267,12 +267,27 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
|
|
|
267
267
|
/**
|
|
268
268
|
* Export p-frame into xsv file
|
|
269
269
|
*
|
|
270
|
-
* @param pf: p-frame - a
|
|
270
|
+
* @param pf: p-frame - a list of p-columns ({data, spec}) or a frame-like map of col.data col.spec entries
|
|
271
271
|
* @param xsvType: string - "csv" or "tsv"
|
|
272
272
|
* @param params: map - export params
|
|
273
273
|
*/
|
|
274
274
|
exportFrame := func(pf, xsvType, params) {
|
|
275
275
|
exportPfTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.xsv-export-pframe")
|
|
276
|
+
|
|
277
|
+
if is_array(pf) {
|
|
278
|
+
// transform into .data .spec map
|
|
279
|
+
|
|
280
|
+
pfm := {}
|
|
281
|
+
i := 0
|
|
282
|
+
for col in pf {
|
|
283
|
+
ll.assert(!is_undefined(col.spec), "expected array of {spec, data} maps as a list of columns, but spec is undefined for: ", col)
|
|
284
|
+
ll.assert(!is_undefined(col.data), "expected array of {spec, data} maps as a list of columns, but data is undefined for: ", col)
|
|
285
|
+
pfm["" + i + ".spec"] = col.spec
|
|
286
|
+
pfm["" + i + ".data"] = col.data
|
|
287
|
+
i = i + 1
|
|
288
|
+
}
|
|
289
|
+
pf = pfm
|
|
290
|
+
}
|
|
276
291
|
|
|
277
292
|
r := render.create(exportPfTpl, {
|
|
278
293
|
pf: pf,
|
|
@@ -7,6 +7,7 @@ ll := import("@platforma-sdk/workflow-tengo:ll")
|
|
|
7
7
|
oop := import("@platforma-sdk/workflow-tengo:oop")
|
|
8
8
|
maps := import("@platforma-sdk/workflow-tengo:maps")
|
|
9
9
|
json := import("json")
|
|
10
|
+
times := import("times")
|
|
10
11
|
constants := import("@platforma-sdk/workflow-tengo:constants")
|
|
11
12
|
|
|
12
13
|
//////////////// definitions ////////////////
|
|
@@ -621,6 +622,73 @@ field = func(f) {
|
|
|
621
622
|
return self.info().Error != 0
|
|
622
623
|
},
|
|
623
624
|
|
|
625
|
+
/**
|
|
626
|
+
* Use cacheMillis, cacheSeconds, cacheMinutes, cacheHours and cacheDays to not make hidden mistakes in cache time ranges.
|
|
627
|
+
* Sets the cache time.
|
|
628
|
+
*
|
|
629
|
+
* @param time: duration - the cache time from 'times' library.
|
|
630
|
+
*/
|
|
631
|
+
setCache: func(time) {
|
|
632
|
+
ll.assert(is_int(time) && time >= times.millisecond,
|
|
633
|
+
"smart.field.setCache: cache time must be an integer >= millisecond. Did you forget to import a standard tengo library 'times'?")
|
|
634
|
+
|
|
635
|
+
tx.cacheSetToField(self.id, time)
|
|
636
|
+
return self
|
|
637
|
+
},
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Sets the cache time in milliseconds.
|
|
641
|
+
*
|
|
642
|
+
* @param millis: number
|
|
643
|
+
*/
|
|
644
|
+
setCacheMillis: func(millis) {
|
|
645
|
+
ll.assert(is_int(millis),
|
|
646
|
+
"smart.field.setCacheMillis: cache time must be a number of milliseconds")
|
|
647
|
+
return self.setCache(millis * times.millisecond)
|
|
648
|
+
},
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Sets the cache time in seconds.
|
|
652
|
+
*
|
|
653
|
+
* @param seconds: number
|
|
654
|
+
*/
|
|
655
|
+
setCacheSeconds: func(seconds) {
|
|
656
|
+
ll.assert(is_int(seconds),
|
|
657
|
+
"smart.field.setCacheSeconds: cache time must be a number of seconds")
|
|
658
|
+
return self.setCache(seconds * times.second)
|
|
659
|
+
},
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Sets the cache time in minutes.
|
|
663
|
+
*
|
|
664
|
+
* @param minutes: number
|
|
665
|
+
*/
|
|
666
|
+
setCacheMinutes: func(minutes) {
|
|
667
|
+
ll.assert(is_int(minutes),
|
|
668
|
+
"smart.field.setCacheMinutes: cache time must be a number of minutes")
|
|
669
|
+
return self.setCache(minutes * times.minute)
|
|
670
|
+
},
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Sets the cache time in hours.
|
|
674
|
+
*
|
|
675
|
+
* @param hours: number
|
|
676
|
+
*/
|
|
677
|
+
setCacheHours: func(hours) {
|
|
678
|
+
ll.assert(is_int(hours), "smart.field.setCacheHours: cache time must be a number of hours")
|
|
679
|
+
return self.setCache(hours * times.hour)
|
|
680
|
+
},
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Sets the cache time in days
|
|
684
|
+
*
|
|
685
|
+
* @param days: number
|
|
686
|
+
*/
|
|
687
|
+
setCacheDays: func(days) {
|
|
688
|
+
ll.assert(is_int(days), "smart.field.setCacheDays: cache time must be a number of days")
|
|
689
|
+
return self.setCache(days * 24 * times.hour)
|
|
690
|
+
},
|
|
691
|
+
|
|
624
692
|
/**
|
|
625
693
|
* Returns a smart.Resource object from the resolved field value
|
|
626
694
|
*/
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|