3
3
namespace Laravel \VaporCli ;
4
4
5
5
use Laravel \VaporCli \Aws \AwsStorageProvider ;
6
- use Laravel \VaporCli \Exceptions \CopyRequestFailedException ;
6
+ use Laravel \VaporCli \Exceptions \RequestFailedException ;
7
7
8
8
class ServeAssets
9
9
{
@@ -18,21 +18,28 @@ class ServeAssets
18
18
public function __invoke (ConsoleVaporClient $ vapor , array $ artifact , $ fresh )
19
19
{
20
20
$ assetPath = Path::build ().'/assets ' ;
21
-
22
- $ requests = $ this ->getAuthorizedAssetRequests (
23
- $ vapor ,
24
- $ artifact ,
25
- $ assetFiles = $ this ->getAssetFiles ($ assetPath ),
26
- $ fresh
27
- );
28
-
29
- $ this ->executeStoreAssetRequests ($ requests ['store ' ], $ assetPath );
30
- $ this ->executeCopyAssetRequests ($ requests ['copy ' ], $ assetPath );
31
-
32
- $ vapor ->recordArtifactAssets (
33
- $ artifact ['id ' ],
34
- $ assetFiles
35
- );
21
+ $ assetFiles = $ this ->getAssetFiles ($ assetPath );
22
+
23
+ collect ($ assetFiles )
24
+ ->chunk (400 )
25
+ ->map
26
+ ->all ()
27
+ ->each (function ($ chunkOfAssetFiles ) use ($ assetPath , $ vapor , $ artifact , $ fresh ) {
28
+ $ requests = $ this ->getAuthorizedAssetRequests (
29
+ $ vapor ,
30
+ $ artifact ,
31
+ $ chunkOfAssetFiles ,
32
+ $ fresh
33
+ );
34
+
35
+ $ this ->executeStoreAssetRequests ($ requests ['store ' ], $ assetPath );
36
+ $ this ->executeCopyAssetRequests ($ requests ['copy ' ], $ assetPath );
37
+
38
+ $ vapor ->recordArtifactAssets (
39
+ $ artifact ['id ' ],
40
+ $ chunkOfAssetFiles
41
+ );
42
+ });
36
43
}
37
44
38
45
/**
@@ -46,14 +53,19 @@ protected function executeStoreAssetRequests($requests, $assetPath)
46
53
{
47
54
$ storage = Helpers::app (AwsStorageProvider::class);
48
55
49
- foreach ($ requests as $ request ) {
50
- Helpers::step ('<comment>Uploading Asset:</comment> ' .$ request ['path ' ].' ( ' .Helpers::kilobytes ($ assetPath .'/ ' .$ request ['path ' ]).') ' );
56
+ if (! empty ($ requests )) {
57
+ try {
58
+ $ storage ->executeStoreRequests ($ requests , $ assetPath , function ($ request ) use ($ assetPath ) {
59
+ Helpers::step ('<comment>Uploading Asset:</comment> ' .$ request ['path ' ].' ( ' .Helpers::kilobytes ($ assetPath .'/ ' .$ request ['path ' ]).') ' );
60
+ });
61
+ } catch (RequestFailedException $ e ) {
62
+ $ request = $ requests [$ e ->getIndex ()];
63
+
64
+ Helpers::line ("<fg=red>Uploading:</> {$ request ['path ' ]}" );
65
+ Helpers::write ($ e ->getMessage ());
51
66
52
- $ storage ->store (
53
- $ request ['url ' ],
54
- array_merge ($ request ['headers ' ], ['Cache-Control ' => 'public, max-age=31536000 ' ]),
55
- $ assetPath .'/ ' .$ request ['path ' ]
56
- );
67
+ exit (1 );
68
+ }
57
69
}
58
70
}
59
71
@@ -68,14 +80,12 @@ protected function executeCopyAssetRequests($requests, $assetPath)
68
80
{
69
81
$ storage = Helpers::app (AwsStorageProvider::class);
70
82
71
- foreach ($ requests as $ request ) {
72
- Helpers::step ('<fg=magenta>Copying Unchanged Asset:</> ' .$ request ['path ' ].' ( ' .Helpers::kilobytes ($ assetPath .'/ ' .$ request ['path ' ]).') ' );
73
- }
74
-
75
83
if (! empty ($ requests )) {
76
84
try {
77
- $ storage ->executeCopyRequests ($ requests );
78
- } catch (CopyRequestFailedException $ e ) {
85
+ $ storage ->executeCopyRequests ($ requests , function ($ request ) use ($ assetPath ) {
86
+ Helpers::step ('<fg=magenta>Copying Unchanged Asset:</> ' .$ request ['path ' ].' ( ' .Helpers::kilobytes ($ assetPath .'/ ' .$ request ['path ' ]).') ' );
87
+ });
88
+ } catch (RequestFailedException $ e ) {
79
89
$ request = $ requests [$ e ->getIndex ()];
80
90
81
91
Helpers::line ("<fg=red>Copying:</> {$ request ['path ' ]}" );
0 commit comments